-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[std/locks]close #7998(complete condition variables) #17711
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
|
This PR workarounds the broadcast problem on genode, it is fixable in the future PR. Ref: https://www.microsoft.com/en-us/research/wp-content/uploads/2004/12/ImplementingCVs.pdf |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I'm not convinced that "broadcast" is a good design. If the threads check for different conditions then all waked up threads would cause contention on the condition variable's lock afterwards... The fact that its support needed these signification Windows API wrapper changes doesn't make it better. What are the use cases for "broadcast"? I have yet to see a convincing one. |
|
For example implementing a barrier: when https://stackoverflow.com/questions/9815798/how-to-find-barrier-functions-implementation
that's true, but we have to wake up all thread. So the usecase
So if tasks are the same, |
|
The spurious wake issue is documented here in the rather short rationale section ([https://pubs.opengroup.org/onlinepubs/009696699/functions/pthread_cond_broadcast.html]) If the intention with what Nim exposes is to provide more Nim specific semantics that apply across systems, as opposed to lightly wrapping, then I can see why we'd want to think deeply about including |
|
At first I thought I could do without broadcast in the However soon enough, I hit an edge case where some other thread than the last, would wake a thread that is not at the current barrier causing the above logic to fail. Point is |
|
Forgot to add that one could make a barrier implementation using atomics. |
How could this happen if every barrier had its own condition variable? But ok, let's have "broadcast" then because all the others have it too, Turning the thundering herd problem into an API, what could go wrong. |
Sorry to be more precise, I meant the local generation count, they are reusable barriers after all. It fits with the rule xflywind mentioned. This is a better explanation than I can provide.
I believe linux solves this with "wait morphing", maybe this is a problem with windows. |
Aha! Good to know! |
…g#17711) * close nim-lang#7998 * workaround genode * Update lib/system/syslocks.nim
Ref timotheecour#693
close #7998
close #17669
genodeOS is still left unchanged, I have no idea.After CI is green, I will add changelog, tests and since.
It is the basis of concurrency programming.
In the future,
Semaphoreshould be exported or re-implemented.