summaryrefslogtreecommitdiff
path: root/sysdeps/l4/pt-thread-halt.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/l4/pt-thread-halt.c')
-rw-r--r--sysdeps/l4/pt-thread-halt.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/sysdeps/l4/pt-thread-halt.c b/sysdeps/l4/pt-thread-halt.c
index 991123c..aa2bf43 100644
--- a/sysdeps/l4/pt-thread-halt.c
+++ b/sysdeps/l4/pt-thread-halt.c
@@ -24,8 +24,22 @@
/* Deallocate the kernel thread resources associated with THREAD. */
void
-__pthread_thread_halt (struct __pthread *thread)
+__pthread_thread_halt (struct __pthread *thread, int need_dealloc)
{
- l4_stop (thread->threadid);
- pthread_pool_add_np (thread->threadid);
+ l4_thread_id_t tid = thread->threadid;
+
+ if (need_dealloc)
+ __pthread_dealloc (thread);
+
+ /* There is potential race here: once if TID is the current thread,
+ then once we add TID to the pool, someone can reallocate it
+ before we call stop. However, to start the thread, the caller
+ atomically starts and sets the sp and ip, thus, if the stop has
+ not yet executed at that point, it won't. */
+
+ if (tid != l4_myself ())
+ l4_stop (tid);
+ pthread_pool_add_np (tid);
+ if (tid == l4_myself ())
+ l4_stop (tid);
}