rust/tests/fail/concurrency/libc_pthread_join_self.rs

23 lines
569 B
Rust
Raw Normal View History

2022-07-08 16:08:32 +00:00
//@ignore-windows: No libc on Windows
// We are making scheduler assumptions here.
2022-07-08 16:08:32 +00:00
//@compile-flags: -Zmiri-preemption-rate=0
2020-04-19 16:42:58 -07:00
// Joining itself is undefined behavior.
#![feature(rustc_private)]
extern crate libc;
2020-04-20 13:22:28 -07:00
use std::{ptr, thread};
2020-04-19 16:42:58 -07:00
fn main() {
2020-04-20 13:22:28 -07:00
let handle = thread::spawn(|| {
unsafe {
let native: libc::pthread_t = libc::pthread_self();
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join itself
}
});
thread::yield_now();
handle.join().unwrap();
2020-04-19 16:42:58 -07:00
}