Skip to content

Commit 8ce98e3

Browse files
authored
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 <[email protected]> Signed-off-by: Harald Hoyer <[email protected]>
1 parent 4899537 commit 8ce98e3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

crates/runtime/src/parking_spot.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ impl ParkingSpot {
115115

116116
let spot = inner.get_mut(&key).expect("failed to get spot");
117117

118-
if !timed_out {
118+
if timed_out {
119+
if let Some(timeout) = timeout {
120+
if Instant::now() < timeout {
121+
// Did not sleep long enough, try again.
122+
continue;
123+
}
124+
}
125+
} else {
119126
if spot.to_unpark == 0 {
120127
continue;
121128
}

0 commit comments

Comments
 (0)