From 2932f048327965731c7e1ab9f2968a2ddb1854f5 Mon Sep 17 00:00:00 2001 From: Jurijs Oniscuks Date: Thu, 5 Jul 2012 14:57:38 +0200 Subject: [PATCH] Fix race condition in pthread_create() Save thread id to *thread_out before new thread is allowed to run else there's a risk that the thread has finished and been deleted when *thread_out is assigned. Change-Id: I6b84c61a8df06840877d4ab036f26feace3192d8 --- libc/bionic/pthread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c index 2e2c09d01..40a09ba6e 100644 --- a/libc/bionic/pthread.c +++ b/libc/bionic/pthread.c @@ -364,10 +364,10 @@ int pthread_create(pthread_t *thread_out, pthread_attr_t const * attr, _thread_created_hook(tid); pthread_mutex_unlock(&gDebuggerNotificationLock); - // Let the thread run. + // Publish the pthread_t and let the thread run. + *thread_out = (pthread_t) thread; pthread_mutex_unlock(start_mutex); - *thread_out = (pthread_t) thread; return 0; }