-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add a documentation for JobSupport.addLastAtomic #3892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
qwwdfsad
commented
Sep 19, 2023
- Document internal invariants
- Add memory footprint test
- This explanation can be used to reasonably review follow-up PR that gets rid of addLastIf
* Document internal invariants * Add memory footprint test * This explanation can be used to reasonably review follow-up PR that gets rid of addLastIf
19b1a2b
to
10c099e
Compare
* If it returns `false` then there is no children to wait for and it's safe to finalize the final job's state. | ||
* Note that at this point, new children can appear: | ||
* * For `cancelling` state they are immediately cancelled. | ||
* * For `completing` state they are not cancelled and left hanging out to dry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to write something meaningful here, but failed to do so.
Here is a more formal description of what it means: #3893
@dkhalanskyjb while you are here, here is the rough outline of the migration plan that minimizes the impact on the codebase (e.g. we don't have to rewrite everything in
The second step is the trickiest one and other is a chance it won't work out, so any critique is welcomed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also (re)move the // This is Harris's RDCSS (Restricted Double-Compare Single Swap) operation
comment, as it's currently pointing to nothing.
Regarding the proposed migration path from DCSS, I think this would lead to the following non-linearizable behavior:
// THREAD A
job.complete()
// THREAD B
job.cancel()
job.isCancelled // true
Job(job)
job.children // doesn't have the new `Job`
job.isCompleted // false
How this could come to be:
- Thread A wants to complete a job. It closes the list but stops before updating the state.
- Thread B wants to cancel a job. It doesn't modify the list, because new children should still be admissible after cancellation, but does update the state. Then, it looks at the job's state and observes that, yes, it's cancelling. Then it attempts to add a new child, but can't, as the list is closed. Regardless of what it does when it observes this inconsistency, then, it observes that the state is not final yet.
Do you see any errors in this logic?
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
Co-authored-by: Dmitry Khalanskiy <[email protected]>
@dkhalanskyjb I see, thanks for the trace. |
I don't understand how this can be achieved in a data-race-free manner and
without blocking synchronization. If you mean double-checking whether the
list is closed after updating the state, almost the same interleaving is
possible, only cancellation should happen in a third thread instead. The
same non-linearizable outputs are still possible if the third thread gets
preempted before it starts the helping.
…On Fri, Oct 20, 2023 at 6:04 PM Vsevolod Tolstopyatov < ***@***.***> wrote:
@dkhalanskyjb <https://github.com/dkhalanskyjb> I see, thanks for the
trace.
It seems like the root of the problem is that we can update the state
without actually touching the tail of the list (or without touching the
list whatsoever), creating a race. Seems like concurrent helping has to be
performed unconditionally
—
Reply to this email directly, view it on GitHub
<#3892 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMT73TJH7Z47I7FDYQ5UR7DYAKOHTAVCNFSM6AAAAAA46N66LWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZTGAYDOMZZGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
There's a scheme for finalization I have far more faith in. It's similar to how DCSS behaves now but without the overly general consensus mechanism:
In essence, If an operation successfully appends to the list, this must have happened before the finalization, as we have an event ordering |