Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use exponential backoff in lock_contended
  • Loading branch information
joboet committed Feb 9, 2024
commit 8db64b5e2d442cb43830a8849e3549e4f8e20447
6 changes: 4 additions & 2 deletions library/std/src/sys/pal/unix/locks/queue_rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ use crate::sync::atomic::{
use crate::sys_common::thread_info;
use crate::thread::Thread;

const SPIN_COUNT: usize = 100;
const SPIN_COUNT: usize = 6;

type State = *mut ();
type AtomicState = AtomicPtr<()>;
Expand Down Expand Up @@ -328,7 +328,9 @@ impl RwLock {
} else if state.addr() & QUEUED == 0 && count < SPIN_COUNT {
// If the lock is not available but no threads are queued, spin
// for a while.
spin_loop();
for _ in 0..(1 << count) {
spin_loop();
}
state = self.state.load(Relaxed);
count += 1;
} else {
Expand Down