Skip to content

Commit

Permalink
fix: prevent optimize of try_lock in park.rs leading to race conditio…
Browse files Browse the repository at this point in the history
…ns (#6355)

* Fixes segfault in park_timeout() on riscv64
  • Loading branch information
leso-kn committed Feb 17, 2024
1 parent b32826b commit 277802d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tokio/src/runtime/scheduler/multi_thread/park.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::loom::sync::{Arc, Condvar, Mutex};
use crate::runtime::driver::{self, Driver};
use crate::util::TryLock;

use std::hint::black_box;
use std::sync::atomic::Ordering::SeqCst;
use std::time::Duration;

Expand Down Expand Up @@ -71,7 +72,7 @@ impl Parker {
// Only parking with zero is supported...
assert_eq!(duration, Duration::from_millis(0));

if let Some(mut driver) = self.inner.shared.driver.try_lock() {
if let Some(mut driver) = black_box(self.inner.shared.driver.try_lock()) {
driver.park_timeout(handle, duration);
}
}
Expand Down

0 comments on commit 277802d

Please sign in to comment.