Skip to content

Commit 321690c

Browse files
committed
Don't spin on contended mutexes.
1 parent 6392f15 commit 321690c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

library/std/src/sys/unix/locks/futex.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ impl Mutex {
7676
// while spinning, to be easier on the caches.
7777
let state = self.futex.load(Relaxed);
7878

79-
if state == 0 || spin == 0 {
79+
// We stop spinning when the mutex is unlocked (0),
80+
// but also when it's contended (2).
81+
if state != 1 || spin == 0 {
8082
return state;
8183
}
8284

0 commit comments

Comments
 (0)