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>
This commit is contained in:
Harald Hoyer
2022-11-22 16:36:29 +01:00
committed by GitHub
parent 4899537328
commit 8ce98e3c12

View File

@@ -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;
}