about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail-dep/concurrency/libc_pthread_join_main.rs
blob: b47c0121a3eee2556ca50c03c3fb848a95329f4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//@ignore-target: windows # No pthreads on Windows

// Joining the main thread is undefined behavior.

use std::{ptr, thread};

fn main() {
    let thread_id: libc::pthread_t = unsafe { libc::pthread_self() };
    let handle = thread::spawn(move || {
        unsafe {
            assert_eq!(libc::pthread_join(thread_id, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join a detached thread
        }
    });
    thread::yield_now();
    handle.join().unwrap();
}