From: Bart Van Assche Date: Tue, 24 Jan 2012 08:30:32 +0000 (+0000) Subject: drd: Avoid that the changes from r12351 trigger a race condition when copying DrdPosi... X-Git-Tag: svn/VALGRIND_3_8_0~501 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38b17ca6f4bedfacb07793f2e8f522e9afd18ab5;p=thirdparty%2Fvalgrind.git drd: Avoid that the changes from r12351 trigger a race condition when copying DrdPosixThreadArgs git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12352 --- diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c index b9bc28e615..5ed4ed9871 100644 --- a/drd/drd_pthread_intercepts.c +++ b/drd/drd_pthread_intercepts.c @@ -146,7 +146,7 @@ typedef struct void* (*start)(void*); void* arg; int detachstate; - DrdSema wrapper_started; + DrdSema* wrapper_started; } DrdPosixThreadArgs; @@ -350,7 +350,7 @@ static void* DRD_(thread_wrapper)(void* arg) * DRD_(set_joinable)() have been invoked to avoid a race with * a pthread_detach() invocation for this thread from another thread. */ - DRD_(sema_up)(&arg_ptr->wrapper_started); + DRD_(sema_up)(arg_copy.wrapper_started); return (arg_copy.start)(arg_copy.arg); } @@ -446,13 +446,15 @@ int pthread_create_intercept(pthread_t* thread, const pthread_attr_t* attr, { int ret; OrigFn fn; + DrdSema wrapper_started; DrdPosixThreadArgs thread_args; VALGRIND_GET_ORIG_FN(fn); + DRD_(sema_init)(&wrapper_started); thread_args.start = start; thread_args.arg = arg; - DRD_(sema_init)(&thread_args.wrapper_started); + thread_args.wrapper_started = &wrapper_started; /* * Find out whether the thread will be started as a joinable thread * or as a detached thread. If no thread attributes have been specified, @@ -471,13 +473,12 @@ int pthread_create_intercept(pthread_t* thread, const pthread_attr_t* attr, CALL_FN_W_WWWW(ret, fn, thread, attr, DRD_(thread_wrapper), &thread_args); DRD_(left_pthread_create)(); - if (ret == 0) - { + if (ret == 0) { /* Wait until the thread wrapper started. */ - DRD_(sema_down)(&thread_args.wrapper_started); + DRD_(sema_down)(&wrapper_started); } - DRD_(sema_destroy)(&thread_args.wrapper_started); + DRD_(sema_destroy)(&wrapper_started); VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DRD_START_NEW_SEGMENT, pthread_self(), 0, 0, 0, 0);