Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion library/std/src/thread/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ impl ThreadId {

// Acquire lock.
let mut spin = 0;
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
// scheduling threads, so avoid `compare_exchange_weak` to avoid spurious yields.
while COUNTER_LOCKED.swap(true, Ordering::Acquire) {
if spin <= 3 {
for _ in 0..(1 << spin) {
spin_loop();
Expand All @@ -80,6 +82,7 @@ impl ThreadId {
}
spin += 1;
}
// This was `false` before the swap, so we got the lock.

// SAFETY: we have an exclusive lock on the counter.
unsafe {
Expand Down
Loading