From 8ce98e3c12482a3f004173a38320394ef673190e Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Tue, 22 Nov 2022 16:36:29 +0100 Subject: [PATCH] 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 Signed-off-by: Harald Hoyer --- crates/runtime/src/parking_spot.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/runtime/src/parking_spot.rs b/crates/runtime/src/parking_spot.rs index a958d6d75a..3b87bd636b 100644 --- a/crates/runtime/src/parking_spot.rs +++ b/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; }