2022-07-08 11:08:32 -05:00
|
|
|
//@compile-flags: -Zmiri-compare-exchange-weak-failure-rate=0.0
|
2022-05-23 03:28:46 -05:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering::*};
|
|
|
|
|
|
|
|
// Ensure that compare_exchange_weak never fails.
|
|
|
|
fn main() {
|
|
|
|
let atomic = AtomicBool::new(false);
|
|
|
|
let tries = 100;
|
|
|
|
for _ in 0..tries {
|
|
|
|
let cur = atomic.load(Relaxed);
|
|
|
|
// Try (weakly) to flip the flag.
|
|
|
|
if atomic.compare_exchange_weak(cur, !cur, Relaxed, Relaxed).is_err() {
|
|
|
|
// We failed. Avoid panic machinery as that uses atomics/locks.
|
|
|
|
eprintln!("compare_exchange_weak failed");
|
|
|
|
std::process::abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|