Capture elapsed duration in Thread::park_timeout example#42597
Capture elapsed duration in Thread::park_timeout example#42597bors merged 1 commit intorust-lang:masterfrom
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.
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.
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.
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
Durationarithmetic is checked, hitting such an edge case will cause a panic.