Skip to content

Commit

Permalink
Merge pull request #4080 from RalfJung/sc-fence-access-test
Browse files Browse the repository at this point in the history
add weak memory consistency test for mixing SC accesses and fences
  • Loading branch information
RalfJung authored Dec 7, 2024
2 parents 0603597 + e52d6d2 commit 35b6409
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/pass/0weak_memory_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,35 @@ fn test_sc_fence_release() {
assert!(!bad);
}

/// Test that SC fences and accesses sync correctly with each other.
fn test_sc_fence_access() {
/*
Wx1 sc
Ry0 sc
||
Wy1 rlx
SC-fence
Rx0 rlx
*/
let x = static_atomic(0);
let y = static_atomic(0);

let j1 = spawn(move || {
x.store(1, SeqCst);
y.load(SeqCst)
});
let j2 = spawn(move || {
y.store(1, Relaxed);
fence(SeqCst);
x.load(Relaxed)
});

let v1 = j1.join().unwrap();
let v2 = j2.join().unwrap();
let bad = v1 == 0 && v2 == 0;
assert!(!bad);
}

pub fn main() {
for _ in 0..50 {
test_single_thread();
Expand All @@ -414,5 +443,6 @@ pub fn main() {
test_cpp20_sc_fence_fix();
test_cpp20_rwc_syncs();
test_sc_fence_release();
test_sc_fence_access();
}
}

0 comments on commit 35b6409

Please sign in to comment.