Merged
Conversation
lithdew
reviewed
Jun 11, 2021
lithdew
reviewed
Jun 11, 2021
|
|
||
| /// Unblocks at most `num_waiters` callers blocked in a `wait()` call on `ptr`. | ||
| /// `num_waiters` of 1 unblocks at most one `wait(ptr, ...)` and `maxInt(u32)` unblocks effectively all `wait(ptr, ...)`. | ||
| pub fn wake(ptr: *const Atomic(u32), num_waiters: u32) void { |
Contributor
There was a problem hiding this comment.
It looks like quite a few platforms only support waking up either 1 or all waiters. What do you think about replacing num_waiters: u32 to wake_all: bool, or replacing wake() with something like notify() (wake one waiter) and broadcast() (wake all waiters)?
Contributor
Author
There was a problem hiding this comment.
num_waiters is more of a hint and can be used to influence the exact count for platforms that support it. Other platforms would just wake up more threads than stated. The waiters already have to handle spurious wake ups, and this keeps it consistent with linux's futex(2) api.
This was referenced Jun 11, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Having a futex primitive is the first step towards building unified/simpler/efficient synchronization primitives. Some notes on platform compatibility:
__ulock_wait/wakeAPI available since 10.12. Its also used in LLVM's libc++/libcxx so it should be still available. There's a possibility it may prevent apps from being uploaded to the AppStore since dynamically linked functions to odd places are checked iirc. If this becomes an issue, we could switch to the generic posix backend.