-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support for Condition Variables #2739
Comments
Condvars don’t really fit here. Notify would be the strategy to use. Does that fit your requirement? |
This is now tracked by #3066 |
Correct me if I am wrong, but I do not think this is implemented. Condition variables work in conjunction with a mutex. There is no straightforward way to do this with Notifier. There needs to be a way to pass a mutex guard to |
I think something like this makes sense to have. Not sure how it fits in with our async mutex though. |
I wrote something like this for my particular use case. Ideally, a similar implementation would be part of
|
Typically you would not pass the lock to the notify methods. By using some different atomic instructions, you can make remove the need for locking around them. Feel free to open a new issue or PR if you have a proposal for adding them. |
Is your feature request related to a problem? Please describe.
Imho, it is fairly unintuitive that there is no equivalence to
std::sync::CondVar
in tokio.Describe the solution you'd like
Provide a
tokio::sync::CondVar
that works withtokio::sync::Mutex
.Describe alternatives you've considered
I tried using the other primitives in
tokio::sync
and ended up using anAtomicUsize
(to track the number of waiting tasks) and atokio::sync::Semaphore
to wake them up. It works but it is kind of ugly.Additional context
Is this something on the todo list for tokio? If not, would patches be accepted? I could probably work on this.
The text was updated successfully, but these errors were encountered: