1 // We want to control preemption here.
2 //@compile-flags: -Zmiri-disable-isolation -Zmiri-preemption-rate=0
3 use std::sync::atomic::{fence, AtomicUsize, Ordering};
6 use std::time::Duration;
10 let a = Arc::new(AtomicUsize::default());
12 thread::spawn(move || {
14 b.store(1, Ordering::SeqCst);
16 thread::sleep(Duration::from_millis(100));
17 fence(Ordering::SeqCst);
18 // Imagine the other thread's actions happening here.
19 assert_eq!(a.load(Ordering::Relaxed), 1);
20 // The fence is useless, since it did not happen-after the `store` in the other thread.
21 // Hence this is a data race.
22 // Also see https://github.com/rust-lang/miri/issues/2192.
23 unsafe { V = 2 } //~ERROR: Data race detected between Write on thread `main` and Write on thread `<unnamed>`