Skip to content

Commit bc59557

Browse files
committed
ThreadId generation fallback path: avoid spurious yields
1 parent 91ab308 commit bc59557

File tree

1 file changed

+3
-1
lines changed
  • library/std/src/thread

1 file changed

+3
-1
lines changed

library/std/src/thread/id.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ impl ThreadId {
7070

7171
// Acquire lock.
7272
let mut spin = 0;
73-
while COUNTER_LOCKED.compare_exchange_weak(false, true, Ordering::Acquire, Ordering::Relaxed).is_err() {
73+
// Miri doesn't like it when we yield here as it interferes with deterministically
74+
// scheduling threads, so use `compare_exchange` to avoid spurious yields.
75+
while COUNTER_LOCKED.compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed).is_err() {
7476
if spin <= 3 {
7577
for _ in 0..(1 << spin) {
7678
spin_loop();

0 commit comments

Comments
 (0)