2022-07-10 19:19:41 -05:00
|
|
|
// We want to control preemption here.
|
|
|
|
//@compile-flags: -Zmiri-disable-isolation -Zmiri-preemption-rate=0
|
2022-07-08 11:08:32 -05:00
|
|
|
//@ignore-windows: Concurrency on Windows is not supported yet.
|
2020-11-06 11:29:54 -06:00
|
|
|
|
|
|
|
use std::mem;
|
2022-06-19 22:33:59 -05:00
|
|
|
use std::thread::{sleep, spawn};
|
|
|
|
use std::time::Duration;
|
2020-11-06 11:29:54 -06:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct EvilSend<T>(pub T);
|
|
|
|
|
|
|
|
unsafe impl<T> Send for EvilSend<T> {}
|
|
|
|
unsafe impl<T> Sync for EvilSend<T> {}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut a = 0u32;
|
|
|
|
let b = &mut a as *mut u32;
|
|
|
|
let c = EvilSend(b);
|
|
|
|
|
|
|
|
let join = unsafe {
|
|
|
|
spawn(move || {
|
|
|
|
*c.0 = 32;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2020-12-09 07:35:42 -06:00
|
|
|
// Detach the thread and sleep until it terminates
|
2020-11-06 11:29:54 -06:00
|
|
|
mem::drop(join);
|
2020-12-09 07:35:42 -06:00
|
|
|
sleep(Duration::from_millis(200));
|
2020-11-06 11:29:54 -06:00
|
|
|
|
|
|
|
// Spawn and immediately join a thread
|
2020-11-27 13:26:06 -06:00
|
|
|
// to execute the join code-path
|
|
|
|
// and ensure that data-race detection
|
|
|
|
// remains enabled nevertheless.
|
2020-11-06 11:29:54 -06:00
|
|
|
spawn(|| ()).join().unwrap();
|
|
|
|
|
|
|
|
unsafe {
|
2022-07-11 06:44:55 -05:00
|
|
|
*c.0 = 64; //~ ERROR: Data race detected between Write on thread `main` and Write on thread `<unnamed>`
|
2020-11-06 11:29:54 -06:00
|
|
|
}
|
|
|
|
}
|