Skip to content

Commit 3ed2c0a

Browse files
committed
Auto merge of rust-lang#2765 - RalfJung:scfix, r=RalfJung
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`
2 parents 9defdc7 + ff5132e commit 3ed2c0a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/tools/miri/tests/pass/0weak_memory_consistency.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,40 @@ fn test_iriw_sc_rlx() {
286286
assert!(c || d);
287287
}
288288

289+
// Another test for C++20 SCfix.
290+
fn scfix() {
291+
let x = static_atomic_bool(false);
292+
let y = static_atomic_bool(false);
293+
294+
let thread1 = spawn(move || {
295+
let a = x.load(Relaxed);
296+
fence(SeqCst);
297+
let b = y.load(Relaxed);
298+
(a, b)
299+
});
300+
301+
let thread2 = spawn(move || {
302+
x.store(true, Relaxed);
303+
});
304+
let thread3 = spawn(move || {
305+
x.store(true, Relaxed);
306+
});
307+
308+
let thread4 = spawn(move || {
309+
let c = y.load(Relaxed);
310+
fence(SeqCst);
311+
let d = x.load(Relaxed);
312+
(c, d)
313+
});
314+
315+
let (a, b) = thread1.join().unwrap();
316+
thread2.join().unwrap();
317+
thread3.join().unwrap();
318+
let (c, d) = thread4.join().unwrap();
319+
let bad = a == true && b == false && c == true && d == false;
320+
assert!(!bad);
321+
}
322+
289323
pub fn main() {
290324
for _ in 0..50 {
291325
test_single_thread();
@@ -297,5 +331,6 @@ pub fn main() {
297331
test_sc_store_buffering();
298332
test_sync_through_rmw_and_fences();
299333
test_iriw_sc_rlx();
334+
scfix();
300335
}
301336
}

0 commit comments

Comments
 (0)