rust/tests/fail/concurrency/windows_join_self.rs

26 lines
646 B
Rust
Raw Normal View History

2022-07-15 03:40:06 -05:00
//@only-target-windows: Uses win32 api functions
// We are making scheduler assumptions here.
//@compile-flags: -Zmiri-preemption-rate=0
// On windows, a thread joining itself is not UB, but it will deadlock.
use std::thread;
extern "system" {
fn GetCurrentThread() -> usize;
fn WaitForSingleObject(handle: usize, timeout: u32) -> u32;
}
const INFINITE: u32 = u32::MAX;
fn main() {
thread::spawn(|| {
unsafe {
let native = GetCurrentThread();
assert_eq!(WaitForSingleObject(native, INFINITE), 0); //~ ERROR: deadlock: the evaluated program deadlocked
}
})
.join()
.unwrap();
}