summaryrefslogtreecommitdiff
path: root/sysdeps/mach/pt-thread-terminate.c
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2014-01-22 01:03:00 +0100
committerRichard Braun <rbraun@sceen.net>2014-01-22 01:03:00 +0100
commit014966443ac044ca9d53b6bcec6678b9360cba78 (patch)
treeee013da78c6c898b94e0e97759c54e051459c8fe /sysdeps/mach/pt-thread-terminate.c
parent9329c3c49fe5f4cde9a84edd5b9b8f26ce38b76e (diff)
Fix thread destruction
Releasing a thread reference uses a mutex, which means the kernel resources used for synchronization must be available until late during the destruction process. For simplicity, merge __pthread_thread_dealloc into __pthread_thread_terminate. * Makefile (libpthread-routines): Remove pt-thread-dealloc. * pthread/pt-create.c (__pthread_create_internal): Remove call to __pthread_thread_dealloc. * pthread/pt-exit.c (__pthread_exit): Likewise. * pthread/pt-internal.h (__pthread_thread_dealloc): Remove declaration. (__pthread_thread_terminate): Update description. * sysdeps/mach/pt-thread-dealloc.c: Remove file. * sysdeps/mach/pt-thread-terminate.c (__pthread_thread_terminate): Destroy the wake up port.
Diffstat (limited to 'sysdeps/mach/pt-thread-terminate.c')
-rw-r--r--sysdeps/mach/pt-thread-terminate.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sysdeps/mach/pt-thread-terminate.c b/sysdeps/mach/pt-thread-terminate.c
index b9d08fc..6672065 100644
--- a/sysdeps/mach/pt-thread-terminate.c
+++ b/sysdeps/mach/pt-thread-terminate.c
@@ -32,7 +32,7 @@ void
__pthread_thread_terminate (struct __pthread *thread)
{
thread_t kernel_thread, self_ktid;
- mach_port_t reply_port;
+ mach_port_t wakeup_port, reply_port;
void *stackaddr;
size_t stacksize;
error_t err;
@@ -50,6 +50,8 @@ __pthread_thread_terminate (struct __pthread *thread)
stacksize = 0;
}
+ wakeup_port = thread->wakeupmsg.msgh_remote_port;
+
/* Each thread has its own reply port, allocated from MiG stub code calling
__mig_get_reply_port. Destroying it is a bit tricky because the calls
involved are also RPCs, causing the creation of a new reply port if
@@ -64,6 +66,9 @@ __pthread_thread_terminate (struct __pthread *thread)
/* Finally done with the thread structure. */
__pthread_dealloc (thread);
+ /* The wake up port is now no longer needed. */
+ __mach_port_destroy (__mach_task_self (), wakeup_port);
+
/* Terminate and release all that's left. */
err = __thread_terminate_release (kernel_thread, mach_task_self (),
kernel_thread, reply_port,