From b9eb71a78f15f5f889114fb1f5393be74789039d Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Sat, 29 Jun 2013 10:48:21 +0200 Subject: Fix a subtle thread creation bug * pthread/pt-create.c (__pthread_create_internal): Store pthread ID in caller-provided memory before starting the new thread. --- pthread/pt-create.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pthread/pt-create.c') diff --git a/pthread/pt-create.c b/pthread/pt-create.c index 9ce0be8..a88c498 100644 --- a/pthread/pt-create.c +++ b/pthread/pt-create.c @@ -195,16 +195,16 @@ __pthread_create_internal (struct __pthread **thread, /* At this point it is possible to guess our pthread ID. We have to make sure that all functions taking a pthread_t argument can - handle the fact that this thread isn't really running yet. */ + handle the fact that this thread isn't really running yet. Since + the new thread might be passed its ID through pthread_create (to + avoid calling pthread_self), read it before starting the thread. */ + *thread = pthread; /* Schedule the new thread. */ err = __pthread_thread_start (pthread); if (err) goto failed_starting; - /* At this point the new thread is up and running. */ - - *thread = pthread; return 0; -- cgit v1.2.3