-
Notifications
You must be signed in to change notification settings - Fork 341
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
Implement async_std::sync::Condvar #369
Conversation
I think notifying another waker when a WaitFuture is dropped with its opt_waker set to None should be enough. This should handle the notify_one well, but it may cause extra tasks being notified if we
Task C will ends up being waken up. However I don't think it's a huge problem, because std's Condvar mentions that:
|
IMO we don't need |
I feel like the wait/wait_timeout are kinda big footguns. If I understand them properly, the returned future will always return Ready the second time they're polled, without necessarily being actually notified. This can happen quite easily by using e.g. the This is technically okay according to Condvars' spurious wakeup conditions, but that is not mentioned at all in the docs. Besides, it seems very trivial to cause a spurious wakeups here compared to on a "normal" blocking implementation, and will likely produce bad, hard to debug code. I kinda question the usefulness of those functions compared to |
Kind of. They will return |
Probably only need to check if |
Yes, but that requires locking the mutex for the wakers when polled, which is doable, but could hurt performance if the condition variable has very much contention. And if |
You need to lock the mutex to remove the waker when cancelling/completing the notify call, or to insert the waker when beginning a new call. I don't see why it'll hurt performance compared to wait_until. |
Ok, I'll take a stab at implementing that. It looks like there is also now a |
@nbdd0121 I think my latest push should address your concerns. |
WakerSet's notify_one does not wake up anything if some task is woken already. This is slightly different from Condvar's notify_one which should always wake up one task (in the case of two concurrent notify_one call for example). |
If i understand the code on master that is how |
Sorry, you're right. That change is introduced in e9edadf which isn't part of a PR so I am not aware of. |
4912fda
to
811280e
Compare
src/sync/condvar.rs
Outdated
|
||
impl fmt::Debug for Condvar { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
//f.debug_struct("Condvar").finish() |
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.
what about this comment?
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.
Some small things and needs a rebase, but other than that I think this looks good and we should really get this in, it is quite a useful primitive
And add warnings about spurious wakeups to wait and wait_timeout
This should also address concerns about spurious wakeups.
And remove an unnneded comment in a Debug implementation
I rebased and addressed your comments. Should I squash as well? |
Thank you |
Part of #217