mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Auto merge of #149481 - RalfJung:threadid-fallback, r=joboet
ThreadId generation fallback path: avoid spurious yields Fixes https://github.com/rust-lang/miri/issues/4737 Alternative to https://github.com/rust-lang/rust/pull/149476 Cc `@orlp` `@joboet`
This commit is contained in:
@@ -70,7 +70,9 @@ fn exhausted() -> ! {
|
||||
|
||||
// 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();
|
||||
@@ -80,6 +82,7 @@ fn exhausted() -> ! {
|
||||
}
|
||||
spin += 1;
|
||||
}
|
||||
// This was `false` before the swap, so we got the lock.
|
||||
|
||||
// SAFETY: we have an exclusive lock on the counter.
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user