Skip to content

Commit 854dcbc

Browse files
committed
add weak memory consistency test for mixing SC accesses and fences
1 parent e82426c commit 854dcbc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: src/tools/miri/tests/pass/0weak_memory_consistency.rs

+30
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,35 @@ fn test_sc_fence_release() {
400400
assert!(!bad);
401401
}
402402

403+
/// Test that SC fences and accesses sync correctly with each other.
404+
fn test_sc_fence_access() {
405+
/*
406+
Wx1 sc
407+
Ry0 sc
408+
||
409+
Wy1 rlx
410+
SC-fence
411+
Rx0 rlx
412+
*/
413+
let x = static_atomic(0);
414+
let y = static_atomic(0);
415+
416+
let j1 = spawn(move || {
417+
x.store(1, SeqCst);
418+
y.load(SeqCst)
419+
});
420+
let j2 = spawn(move || {
421+
y.store(1, Relaxed);
422+
fence(SeqCst);
423+
x.load(Relaxed)
424+
});
425+
426+
let v1 = j1.join().unwrap();
427+
let v2 = j2.join().unwrap();
428+
let bad = v1 == 0 && v2 == 0;
429+
assert!(!bad);
430+
}
431+
403432
pub fn main() {
404433
for _ in 0..50 {
405434
test_single_thread();
@@ -414,5 +443,6 @@ pub fn main() {
414443
test_cpp20_sc_fence_fix();
415444
test_cpp20_rwc_syncs();
416445
test_sc_fence_release();
446+
test_sc_fence_access();
417447
}
418448
}

0 commit comments

Comments
 (0)