Skip to content
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

CondVar wait functions accepting a closure #47960

Closed
vlovich opened this issue Feb 2, 2018 · 6 comments · Fixed by #67076
Closed

CondVar wait functions accepting a closure #47960

vlovich opened this issue Feb 2, 2018 · 6 comments · Fixed by #67076
Labels
A-concurrency Area: Concurrency B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@vlovich
Copy link

vlovich commented Feb 2, 2018

Pretty common for conditional variable classes to provide wait variants that accept a closure that returns a boolean indicating whether or not the condition has been satisfied. This would be a pretty nice ergonomic improvement to using CondVar. Something like cvar.wait_until(lock, || { some condition }). Even more useful would be a wait_timeout_until which would avoid the need to keep track of elapsed time if the condition variable might get notified several times before the condition is met.

@steveklabnik
Copy link
Member

Generally, for small features, we just take PRs, and for big ones, issues. I'm not sure if @rust-lang/libs considers this a small or large feature.

@aturon
Copy link
Member

aturon commented Feb 2, 2018

This seems small enough for a direct PR, yes.

@vlovich
Copy link
Author

vlovich commented Feb 2, 2018

Will prepare it. Still a little new to rust. Would the callback be Fn or FnMut?

@sfackler
Copy link
Member

sfackler commented Feb 2, 2018

FnMut - closures should generally be as flexible as possible.

@cuviper cuviper added A-concurrency Area: Concurrency T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Feb 2, 2018
@dtolnay dtolnay added C-feature-accepted Category: A feature request that has been accepted pending implementation. and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Feb 16, 2018
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 25, 2018
Add Condvar APIs not susceptible to spurious wake

Provide wait_until and wait_timeout_until helper wrappers that aren't susceptible to spurious wake.
Additionally wait_timeout_until makes it possible to more easily write code that waits for a fixed amount of time in face of spurious wakes since otherwise each user would have to do math on adjusting the duration.

Implements rust-lang#47960.
kennytm added a commit to kennytm/rust that referenced this issue Feb 25, 2018
Add Condvar APIs not susceptible to spurious wake

Provide wait_until and wait_timeout_until helper wrappers that aren't susceptible to spurious wake.
Additionally wait_timeout_until makes it possible to more easily write code that waits for a fixed amount of time in face of spurious wakes since otherwise each user would have to do math on adjusting the duration.

Implements rust-lang#47960.
@jonas-schievink jonas-schievink added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC B-unstable Blocker: Implemented in the nightly compiler and unstable. and removed C-feature-accepted Category: A feature request that has been accepted pending implementation. labels Mar 24, 2019
@grantslatton
Copy link

Is anything preventing stabilization of this?

@mbrubeck
Copy link
Contributor

mbrubeck commented Dec 5, 2019

@rust-lang/libs can I nominate this for stabilization? We've been using these in the code base at my job for a while, and we'd love to move to stable Rust soon without needing to shim these out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-concurrency Area: Concurrency B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
9 participants