Skip to content

Commit

Permalink
Auto merge of #2148 - RalfJung:compare-exchange-weak-failure-rate-tes…
Browse files Browse the repository at this point in the history
…t, r=RalfJung

test that compare-exchange-weak-failure-rate=0.0 means what it says

Adds a test for #2105
  • Loading branch information
bors committed May 23, 2022
2 parents c51cd7a + 5ed22b3 commit 27b40f1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/run-pass/atomic-compare-exchange-weak-never-fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// compile-flags: -Zmiri-compare-exchange-weak-failure-rate=0.0
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();
}
}
}

0 comments on commit 27b40f1

Please sign in to comment.