Browse Source

fix: atomit wait does not sleep long enough (#5315)

From the documentation of `CondVar::wait_timeout`:

> The semantics of this function are equivalent to wait except that the thread
> will be blocked for roughly no longer than `dur`. This method should not be
> used for precise timing due to anomalies such as preemption or platform
> differences that might not cause the maximum amount of time waited to be
> precisely `dur`.

Therefore, go to sleep again, if the thread has not slept long enough.

Signed-off-by: Harald Hoyer <harald@profian.com>

Signed-off-by: Harald Hoyer <harald@profian.com>
pull/5385/head
Harald Hoyer 2 years ago
committed by GitHub
parent
commit
8ce98e3c12
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      crates/runtime/src/parking_spot.rs

9
crates/runtime/src/parking_spot.rs

@ -115,7 +115,14 @@ impl ParkingSpot {
let spot = inner.get_mut(&key).expect("failed to get spot");
if !timed_out {
if timed_out {
if let Some(timeout) = timeout {
if Instant::now() < timeout {
// Did not sleep long enough, try again.
continue;
}
}
} else {
if spot.to_unpark == 0 {
continue;
}

Loading…
Cancel
Save