]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fixed another unintended data race.
authorBart Van Assche <bvanassche@acm.org>
Sun, 8 Mar 2009 19:02:59 +0000 (19:02 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 8 Mar 2009 19:02:59 +0000 (19:02 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9326

drd/tests/linuxthreads_det.c

index ec3e8edc5f00594a5a5c93b00db33e5e2d3f440b..8343172bd7374cb77d3cd9a9dc46aadecb30bf1d 100644 (file)
@@ -8,11 +8,18 @@
 #include <unistd.h>
 
 
+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;
 }