Skip to content

Implement Thread::park_timeout #21788

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

Merged
merged 1 commit into from
Feb 1, 2015
Merged

Implement Thread::park_timeout #21788

merged 1 commit into from
Feb 1, 2015

Conversation

carllerche
Copy link
Member

The implementation is similar to Thread::park

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@carllerche
Copy link
Member Author

Woops, I am noticing botched docs. Fixed

@brson
Copy link
Contributor

brson commented Jan 30, 2015

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned brson Jan 30, 2015
pub fn park_timeout(dur: Duration) {
let thread = Thread::current();
let mut guard = thread.inner.lock.lock().unwrap();
let (mut guard, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be wrapped in while !*guard like the loop above? Otherwise this will block no matter what even if a previous unpark was seen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. :( I have failed.

@alexcrichton
Copy link
Member

Could you also add a test for this? A few simple smoke tests should be fine, but largely just something that calls the functions.

@carllerche
Copy link
Member Author

Done

@alexcrichton
Copy link
Member

@bors: r+ 60ba03d

Thanks!

bors added a commit that referenced this pull request Feb 1, 2015
The implementation is similar to `Thread::park`
@bors
Copy link
Collaborator

bors commented Feb 1, 2015

⌛ Testing commit 60ba03d with merge fe4340a...

@bors bors merged commit 60ba03d into rust-lang:master Feb 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants