rust/tests/compile-fail/concurrency/libc_pthread_join_main.rs

21 lines
559 B
Rust
Raw Normal View History

2020-04-26 16:24:48 -05:00
// ignore-windows: Concurrency on Windows is not supported yet.
// Joining the main thread is undefined behavior.
#![feature(rustc_private)]
extern crate libc;
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 or already joined thread
}
});
thread::yield_now();
handle.join().unwrap();
}