about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail-dep/concurrency/windows_join_main.rs
blob: da549a8d117d0e424034ec70d3da42d608229409 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//@only-target: windows # Uses win32 api functions
// We are making scheduler assumptions here.
//@compile-flags: -Zmiri-deterministic-concurrency
//@error-in-other-file: deadlock

// On windows, joining main is not UB, but it will block a thread forever.

use std::thread;

use windows_sys::Win32::Foundation::{HANDLE, WAIT_OBJECT_0};
use windows_sys::Win32::System::Threading::{INFINITE, WaitForSingleObject};

// XXX HACK: This is how miri represents the handle for thread 0.
// This value can be "legitimately" obtained by using `GetCurrentThread` with `DuplicateHandle`
// but miri does not implement `DuplicateHandle` yet.
const MAIN_THREAD: HANDLE = (2i32 << 29) as HANDLE;

fn main() {
    thread::spawn(|| {
        unsafe {
            assert_eq!(WaitForSingleObject(MAIN_THREAD, INFINITE), WAIT_OBJECT_0); //~ ERROR: deadlock
        }
    })
    .join()
    .unwrap();
}