Skip to content

Commit ff5e35b

Browse files
author
Vytautas Astrauskas
committed
Added a test that joining main is UB.
1 parent bc9d007 commit ff5e35b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
3+
// Joining the main thread is undefined behavior.
4+
5+
#![feature(rustc_private)]
6+
7+
extern crate libc;
8+
9+
use std::{ptr, thread};
10+
11+
fn main() {
12+
let thread_id: libc::pthread_t = unsafe { libc::pthread_self() };
13+
let handle = thread::spawn(move || {
14+
unsafe {
15+
assert_eq!(libc::pthread_join(thread_id, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join a detached or already joined thread
16+
}
17+
});
18+
thread::yield_now();
19+
handle.join().unwrap();
20+
}

0 commit comments

Comments
 (0)