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

Capture elapsed duration in Thread::park_timeout example #42597

Merged
merged 1 commit into from
Jun 14, 2017

Conversation

mark-buer
Copy link
Contributor

beginning_park.elapsed() might return a larger value within the loop as compared to that checked in the loop conditional.
Since Duration arithmetic is checked, hitting such an edge case will cause a panic.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (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. Due to 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 the contribution instructions for more information.

@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 12, 2017
@carols10cents
Copy link
Member

Thank you! We'll periodically check in to make sure that @alexcrichton or someone else from the team reviews this soon :)

/// loop {
/// park_timeout(timeout_remaining);
/// let elapsed = beginning_park.elapsed();
/// if elapsed >= timeout {
Copy link
Member

Choose a reason for hiding this comment

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

I think this should compare against timeout_remaining, right?

Similarly, below the subtraction should be against timeout_remaining instead of timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, I think it is right as-is.

In the loop, elapsed is the total duration since creation of beginning_park (created outside of the loop). It is a rough measure of the total duration we've parked for thus far.
timeout is the total desired park duration.
Thus, comparing the two seems okay (we're comparing two "totals").
If we need to park some more, we calculate the difference between the total desired park duration and the total elapsed park duration, and use that value in yet-another-park.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right yes sorry got mixed up!

@alexcrichton
Copy link
Member

Thanks for the PR @mark-buer!

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jun 13, 2017

📌 Commit 0389d40 has been approved by alexcrichton

@arielb1 arielb1 added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 13, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Jun 13, 2017
… r=alexcrichton

Capture elapsed duration in Thread::park_timeout example

`beginning_park.elapsed()` might return a larger value within the loop as compared to that checked in the loop conditional.
Since `Duration` arithmetic is checked, hitting such an edge case will cause a panic.
bors added a commit that referenced this pull request Jun 14, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Rollup of 6 pull requests

- Successful merges: #42408, #42428, #42496, #42597, #42636, #42638
- Failed merges: #42612
@bors bors merged commit 0389d40 into rust-lang:master Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants