]> git.lizzy.rs Git - rust.git/blob - tests/fail/data_race/atomic_read_na_write_race1.rs
get rid of some uses of core_intrinsics
[rust.git] / tests / fail / data_race / atomic_read_na_write_race1.rs
1 // We want to control preemption here.
2 //@compile-flags: -Zmiri-preemption-rate=0
3 //@ignore-target-windows: Concurrency on Windows is not supported yet.
4
5 use std::sync::atomic::{AtomicUsize, Ordering};
6 use std::thread::spawn;
7
8 #[derive(Copy, Clone)]
9 struct EvilSend<T>(pub T);
10
11 unsafe impl<T> Send for EvilSend<T> {}
12 unsafe impl<T> Sync for EvilSend<T> {}
13
14 pub fn main() {
15     let mut a = AtomicUsize::new(0);
16     let b = &mut a as *mut AtomicUsize;
17     let c = EvilSend(b);
18     unsafe {
19         let j1 = spawn(move || {
20             *(c.0 as *mut usize) = 32;
21         });
22
23         let j2 = spawn(move || {
24             (&*c.0).load(Ordering::SeqCst) //~ ERROR: Data race detected between Atomic Load on thread `<unnamed>` and Write on thread `<unnamed>`
25         });
26
27         j1.join().unwrap();
28         j2.join().unwrap();
29     }
30 }