From 3a54aa778d29b1e02706fef3925a523f43e07463 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sat, 9 Dec 2023 13:24:31 +0100 Subject: [PATCH] Fix thread cleanup after main exits. --- src/pthread/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pthread/mod.rs b/src/pthread/mod.rs index ce380d92db..0da0bfde69 100644 --- a/src/pthread/mod.rs +++ b/src/pthread/mod.rs @@ -254,8 +254,6 @@ pub unsafe fn join(thread: &Pthread) -> Result { // pthread_t of this thread, will no longer be valid. In practice, we can thus deallocate the // thread state. - OS_TID_TO_PTHREAD.lock().remove(&thread.os_tid.get().read()); - dealloc_thread(thread); Ok(retval) @@ -311,6 +309,7 @@ pub unsafe fn exit_current_thread(retval: Retval) -> ! { // On the other hand, there can be at most two strong references to each thread (OS_TID_TO_PTHREAD // and PTHREAD_SELF), so maybe Arc is unnecessary except from being memory-safe. unsafe fn dealloc_thread(thread: &Pthread) { + OS_TID_TO_PTHREAD.lock().remove(&thread.os_tid.get().read()); drop(Box::from_raw(thread as *const Pthread as *mut Pthread)); } pub const SIGRT_RLCT_CANCEL: usize = 32;