Skip to content

Commit e7c2694

Browse files
author
Vytautas Astrauskas
committed
Make the main thread detached.
1 parent 69eaaad commit e7c2694

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/thread.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ impl<'mir, 'tcx> Default for ThreadManager<'mir, 'tcx> {
177177
fn default() -> Self {
178178
let mut threads = IndexVec::new();
179179
// Create the main thread and add it to the list of threads.
180-
threads.push(Default::default());
180+
let mut main_thread = Thread::default();
181+
main_thread.join_status = ThreadJoinStatus::Detached;
182+
threads.push(main_thread);
181183
Self {
182184
active_thread: ThreadId::new(0),
183185
threads: threads,

tests/compile-fail/concurrency/libc_pthread_join_self.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
extern crate libc;
88

9-
use std::ptr;
9+
use std::{ptr, thread};
1010

1111
fn main() {
12-
unsafe {
13-
let native: libc::pthread_t = libc::pthread_self();
14-
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join itself
15-
}
12+
let handle = thread::spawn(|| {
13+
unsafe {
14+
let native: libc::pthread_t = libc::pthread_self();
15+
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0); //~ ERROR: Undefined Behavior: trying to join itself
16+
}
17+
});
18+
thread::yield_now();
19+
handle.join().unwrap();
1620
}

0 commit comments

Comments
 (0)