From 49618ea5747b5d87c9360b7bd1e75d276b47fde0 Mon Sep 17 00:00:00 2001 From: Stefan Ring Date: Mon, 18 Apr 2011 21:03:42 +0200 Subject: [PATCH] * src/threads/posix/thread-posix.cpp: Take care not to signal threads after they have stopped existing. --- src/threads/posix/thread-posix.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/threads/posix/thread-posix.cpp b/src/threads/posix/thread-posix.cpp index 1d9b3881e..820d7260e 100644 --- a/src/threads/posix/thread-posix.cpp +++ b/src/threads/posix/thread-posix.cpp @@ -1005,6 +1005,10 @@ bool thread_detach_current_thread(void) /* XXX Care about exceptions? */ (void) lock_monitor_exit(jlt.get_handle()); + t->waitmutex->lock(); + t->tid = 0; + t->waitmutex->unlock(); + /* Enter the join-mutex before calling thread_free, so threads_join_all_threads gets the correct number of non-daemon threads. */ @@ -1020,6 +1024,9 @@ bool thread_detach_current_thread(void) cond_join->signal(); threads_mutex_join_unlock(); + t->suspendmutex->lock(); + t->suspendmutex->unlock(); + return true; } @@ -1104,6 +1111,8 @@ bool threads_suspend_thread(threadobject *thread, int32_t reason) } else { // Send the suspend signal to the other thread. + if (!thread->tid) + return false; if (pthread_kill(thread->tid, SIGUSR1) != 0) os::abort_errno("threads_suspend_thread: pthread_kill failed"); @@ -1401,7 +1410,8 @@ void threads_thread_interrupt(threadobject *t) /* Interrupt blocking system call using a signal. */ - pthread_kill(t->tid, Signal_INTERRUPT_SYSTEM_CALL); + if (t->tid) + pthread_kill(t->tid, Signal_INTERRUPT_SYSTEM_CALL); t->waitcond->signal(); -- 2.25.1