1
Fork 0

Merge pull request #4080 from RalfJung/sc-fence-access-test

add weak memory consistency test for mixing SC accesses and fences
This commit is contained in:
Ralf Jung 2024-12-07 17:39:58 +00:00 committed by GitHub
commit 6956b4165f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();
@ -414,5 +443,6 @@ pub fn main() {
test_cpp20_sc_fence_fix();
test_cpp20_rwc_syncs();
test_sc_fence_release();
test_sc_fence_access();
}
}