We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents dfe1b8c + 14830bf commit f783ddeCopy full SHA for f783dde
library/std/src/thread/id.rs
@@ -70,7 +70,9 @@ impl ThreadId {
70
71
// Acquire lock.
72
let mut spin = 0;
73
- while COUNTER_LOCKED.compare_exchange_weak(false, true, Ordering::Acquire, Ordering::Relaxed).is_err() {
+ // Miri doesn't like it when we yield here as it interferes with deterministically
74
+ // scheduling threads, so avoid `compare_exchange_weak` to avoid spurious yields.
75
+ while COUNTER_LOCKED.swap(true, Ordering::Acquire) {
76
if spin <= 3 {
77
for _ in 0..(1 << spin) {
78
spin_loop();
@@ -80,6 +82,7 @@ impl ThreadId {
80
82
}
81
83
spin += 1;
84
85
+ // This was `false` before the swap, so we got the lock.
86
87
// SAFETY: we have an exclusive lock on the counter.
88
unsafe {
0 commit comments