From: Bart Van Assche Date: Sun, 8 Mar 2009 19:02:59 +0000 (+0000) Subject: Fixed another unintended data race. X-Git-Tag: svn/VALGRIND_3_5_0~898 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f21ce13492f55eaf406512a452ef974dee2bb1dc;p=thirdparty%2Fvalgrind.git Fixed another unintended data race. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9326 --- diff --git a/drd/tests/linuxthreads_det.c b/drd/tests/linuxthreads_det.c index ec3e8edc5f..8343172bd7 100644 --- a/drd/tests/linuxthreads_det.c +++ b/drd/tests/linuxthreads_det.c @@ -8,11 +8,18 @@ #include +static pthread_mutex_t s_mutex; static pid_t s_main_thread_pid; void* thread_func(void* arg) { + pid_t main_thread_pid; + + pthread_mutex_lock(&s_mutex); + main_thread_pid = s_main_thread_pid; + pthread_mutex_unlock(&s_mutex); + if (s_main_thread_pid == getpid()) { write(STDOUT_FILENO, "NPTL or non-Linux POSIX threads implementation detected.\n", 57); @@ -28,8 +35,15 @@ int main(int argc, char** argv) { pthread_t threadid; + pthread_mutex_init(&s_mutex, 0); + + pthread_mutex_lock(&s_mutex); s_main_thread_pid = getpid(); + pthread_mutex_unlock(&s_mutex); pthread_create(&threadid, 0, thread_func, 0); pthread_join(threadid, 0); + + pthread_mutex_destroy(&s_mutex); + return 0; }