]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Eliminate a superfluous sleep() call and check the pthread_cond_wait() return value
authorBart Van Assche <bvanassche@acm.org>
Wed, 27 Jul 2011 08:49:47 +0000 (08:49 +0000)
committerBart Van Assche <bvanassche@acm.org>
Wed, 27 Jul 2011 08:49:47 +0000 (08:49 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11924

drd/tests/pth_detached.c

index 88d22d9b38a1b54a2e5cdba2570435b451a94cad..f3025c162eca1555bdc3aa4eb46a74ec3fb5fa59 100644 (file)
@@ -7,7 +7,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-static int s_finished_count;
+static int s_finished_count; /* protected by s_mutex */
 static pthread_mutex_t s_mutex;
 static pthread_cond_t s_cond;
 
@@ -70,16 +70,15 @@ int main(int argc, char** argv)
 
   // Wait until all detached threads have written their output to stdout.
   pthread_mutex_lock(&s_mutex);
-  while (s_finished_count < count1 + count2
-         && pthread_cond_wait(&s_cond, &s_mutex) == 0)
-    ;
+  while (s_finished_count < count1 + count2) {
+    const int ret = pthread_cond_wait(&s_cond, &s_mutex);
+    assert(ret == 0);
+  }
   pthread_mutex_unlock(&s_mutex);
 
   pthread_cond_destroy(&s_cond);
   pthread_mutex_destroy(&s_mutex);
 
-  sleep(1);
-
   write(STDOUT_FILENO, "\n", 1);
 
   return 0;