summaryrefslogtreecommitdiff
path: root/pthread/pt-join.c
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@gnu.org>2008-08-16 13:13:07 +0000
committerThomas Schwinge <tschwinge@gnu.org>2009-04-07 23:57:46 +0200
commit2e166e1a00928d5a31f00c185c2464b2146d6f6a (patch)
tree7068aa7ad8a6aa59e798df40033bfdb480dcd801 /pthread/pt-join.c
parent61585a1da2ce36b0db1cbc9673456205d5111e78 (diff)
2008-08-16 Neal H. Walfield <neal@gnu.org>
* pthread/pt-alloc.c: Don't include <bits/atomic.h>. (__pthread_free_threads): Change to a struct __pthread *. (__pthread_free_threads_lock): New variable. (__pthread_alloc): When looking for a TCB to reuse, iterate over __pthread_free_threads taking the first for which the STATE field is PTHREAD_TERMINATED. When reusing a TCB, first call __pthread_thread_halt on it. * pthread/pt-dealloc.c: Don't include <bits/atomic.h>. (__pthread_free_threads): Change to a struct __pthread *. (__pthread_free_threads_lock): New declaration. (__pthread_dealloc): Enqueue PTHREAD on __PTHREAD_FREE_THREADS. Set PTHREAD->STATE to PTHREAD_TERMINATED after everything else. * 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. * pthread/pt-internal.h (__pthread_thread_halt): Remove argument NEED_DEALLOC. Update users. * sysdeps/mach/pt-thread-halt.c (__pthread_thread_halt): Remove argument need_dealloc. * sysdeps/mach/hurd/pt-sysdep.h (PTHREAD_SYSDEP_MEMBERS): Add field have_kernel_resources. * sysdeps/mach/hurd/pt-thread-alloc.c (__pthread_thread_alloc): If THREAD->HAVE_KERNEL_RESOURCES is true, just return. After allocating the resources, set THREAD->HAVE_KERNEL_RESOURCES to true.
Diffstat (limited to 'pthread/pt-join.c')
-rw-r--r--pthread/pt-join.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/pthread/pt-join.c b/pthread/pt-join.c
index 06e9f1f..153058b 100644
--- a/pthread/pt-join.c
+++ b/pthread/pt-join.c
@@ -54,12 +54,20 @@ pthread_join (pthread_t thread, void **status)
if (status)
*status = pthread->status;
- /* Make sure nobody can reference it anymore, and mark it as
- terminated. */
+ /* 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;