Skip to content

Commit 5ed22b3

Browse files
committed
test that compare-exchange-weak-failure-rate=0.0 means what it says
1 parent ab03d32 commit 5ed22b3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -Zmiri-compare-exchange-weak-failure-rate=0.0
2+
use std::sync::atomic::{AtomicBool, Ordering::*};
3+
4+
// Ensure that compare_exchange_weak never fails.
5+
fn main() {
6+
let atomic = AtomicBool::new(false);
7+
let tries = 100;
8+
for _ in 0..tries {
9+
let cur = atomic.load(Relaxed);
10+
// Try (weakly) to flip the flag.
11+
if atomic.compare_exchange_weak(cur, !cur, Relaxed, Relaxed).is_err() {
12+
// We failed. Avoid panic machinery as that uses atomics/locks.
13+
eprintln!("compare_exchange_weak failed");
14+
std::process::abort();
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)