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

// Joining an already joined thread is undefined behavior.

use std::{mem, ptr};

extern "C" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
    ptr::null_mut()
}

fn main() {
    unsafe {
        let mut native: libc::pthread_t = mem::zeroed();
        assert_eq!(
            libc::pthread_create(&mut native, ptr::null(), thread_start, ptr::null_mut()),
            0
        );
        assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
        assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join an already joined thread
    }
}