From 8db64b5e2d442cb43830a8849e3549e4f8e20447 Mon Sep 17 00:00:00 2001 From: joboet Date: Tue, 18 Apr 2023 19:01:37 +0200 Subject: [PATCH] use exponential backoff in `lock_contended` --- library/std/src/sys/pal/unix/locks/queue_rwlock.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/pal/unix/locks/queue_rwlock.rs b/library/std/src/sys/pal/unix/locks/queue_rwlock.rs index 1a485b01f71c..315c59a02d55 100644 --- a/library/std/src/sys/pal/unix/locks/queue_rwlock.rs +++ b/library/std/src/sys/pal/unix/locks/queue_rwlock.rs @@ -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<()>; @@ -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 {