Skip to content

Commit a2467c9

Browse files
committed
Add C++20 SC access test
1 parent 01dffe0 commit a2467c9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/pass/0weak_memory_consistency.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,35 @@ fn test_sync_through_rmw_and_fences() {
257257
assert_ne!((a, b), (0, 0));
258258
}
259259

260+
// Test case by @SabrinaJewson
261+
// https://github.com/rust-lang/miri/issues/2301#issuecomment-1221502757
262+
// Demonstrating C++20 SC access changes
263+
fn test_iriw_sc_rlx() {
264+
let x = static_atomic_bool(false);
265+
let y = static_atomic_bool(false);
266+
267+
x.store(false, Relaxed);
268+
y.store(false, Relaxed);
269+
270+
let a = spawn(move || x.store(true, Relaxed));
271+
let b = spawn(move || y.store(true, Relaxed));
272+
let c = spawn(move || {
273+
while !x.load(SeqCst) {}
274+
y.load(SeqCst)
275+
});
276+
let d = spawn(move || {
277+
while !y.load(SeqCst) {}
278+
x.load(SeqCst)
279+
});
280+
281+
a.join().unwrap();
282+
b.join().unwrap();
283+
let c = c.join().unwrap();
284+
let d = d.join().unwrap();
285+
286+
assert!(c || d);
287+
}
288+
260289
pub fn main() {
261290
for _ in 0..50 {
262291
test_single_thread();
@@ -267,5 +296,6 @@ pub fn main() {
267296
test_corr();
268297
test_sc_store_buffering();
269298
test_sync_through_rmw_and_fences();
299+
test_iriw_sc_rlx();
270300
}
271301
}

0 commit comments

Comments
 (0)