Skip to content

Commit 8db64b5

Browse files
committed
use exponential backoff in lock_contended
1 parent 61ce691 commit 8db64b5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

library/std/src/sys/pal/unix/locks/queue_rwlock.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ use crate::sync::atomic::{
114114
use crate::sys_common::thread_info;
115115
use crate::thread::Thread;
116116

117-
const SPIN_COUNT: usize = 100;
117+
const SPIN_COUNT: usize = 6;
118118

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

0 commit comments

Comments
 (0)