summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@gnu.org>2008-08-16 11:28:22 +0000
committerThomas Schwinge <tschwinge@gnu.org>2009-04-07 23:55:50 +0200
commit5b282fd9ecf9cb39a0f66285ae8caa5567e265b0 (patch)
tree26df3387383d922b635ca193c596b1c5cedb81b1
parentfc2a4800e8fadcc7e9bbd880cc3405d5a088669f (diff)
2008-08-16 Neal H. Walfield <neal@gnu.org>
* pthread/pt-detach.c (pthread_detach): If destroying the thread, call __pthread_thread_halt before deallocating the stack. In this case, also call __pthread_thread_dealloc on the tcb.
-rw-r--r--ChangeLog3
-rw-r--r--pthread/pt-detach.c10
2 files changed, 13 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7bd9ee7..35565d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,9 @@
* pthread/pt-join.c (pthread_join): Call __pthread_thread_halt
before destroying the thread. When destroying the thread, call
__pthread_thread_dealloc on it.
+ * pthread/pt-detach.c (pthread_detach): If destroying the thread,
+ call __pthread_thread_halt before deallocating the stack. In this
+ case, also call __pthread_thread_dealloc on the tcb.
* pthread/pt-exit.c (pthread_exit): Call __pthread_dealloc only if
the thread is detached and then as the last thing we do before
calling __pthread_thread_halt.
diff --git a/pthread/pt-detach.c b/pthread/pt-detach.c
index 42a8408..1e42c45 100644
--- a/pthread/pt-detach.c
+++ b/pthread/pt-detach.c
@@ -58,10 +58,20 @@ pthread_detach (pthread_t thread)
__pthread_mutex_unlock (&pthread->state_lock);
+ /* Make sure the thread is not running before we remove its
+ stack. (The only possibility is that it is in a call to
+ __pthread_thread_halt itself, but that is enough to cause a
+ sigsegv.) */
+ __pthread_thread_halt (pthread);
+
+ /* Destroy the stack, the kernel resources and the control
+ block. */
assert (pthread->stack);
__pthread_stack_dealloc (pthread->stackaddr, pthread->stacksize);
pthread->stack = 0;
+ __pthread_thread_dealloc (pthread);
+
__pthread_dealloc (pthread);
break;