Skip to content

Commit

Permalink
Auto merge of rust-lang#2765 - RalfJung:scfix, r=RalfJung
Browse files Browse the repository at this point in the history
add scfix test

I'm not sure if we currently *guarantee* to pass this test, but at least I was unable to get it to fail.

Cc `@cbeuw`
  • Loading branch information
bors committed Jan 25, 2023
2 parents 4b775bc + 5d4ec54 commit a450c39
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/tools/miri/tests/pass/0weak_memory_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,40 @@ fn test_iriw_sc_rlx() {
assert!(c || d);
}

// Another test for C++20 SCfix.
fn scfix() {
let x = static_atomic_bool(false);
let y = static_atomic_bool(false);

let thread1 = spawn(move || {
let a = x.load(Relaxed);
fence(SeqCst);
let b = y.load(Relaxed);
(a, b)
});

let thread2 = spawn(move || {
x.store(true, Relaxed);
});
let thread3 = spawn(move || {
x.store(true, Relaxed);
});

let thread4 = spawn(move || {
let c = y.load(Relaxed);
fence(SeqCst);
let d = x.load(Relaxed);
(c, d)
});

let (a, b) = thread1.join().unwrap();
thread2.join().unwrap();
thread3.join().unwrap();
let (c, d) = thread4.join().unwrap();
let bad = a == true && b == false && c == true && d == false;
assert!(!bad);
}

pub fn main() {
for _ in 0..50 {
test_single_thread();
Expand All @@ -297,5 +331,6 @@ pub fn main() {
test_sc_store_buffering();
test_sync_through_rmw_and_fences();
test_iriw_sc_rlx();
scfix();
}
}

0 comments on commit a450c39

Please sign in to comment.