-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Conversation
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. |
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 { |
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.
I think this should compare against timeout_remaining
, right?
Similarly, below the subtraction should be against timeout_remaining
instead of timeout
?
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.
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.
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.
Ah right yes sorry got mixed up!
Thanks for the PR @mark-buer! |
@bors: r+ |
📌 Commit 0389d40 has been approved by |
… 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.
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.