]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
The dots (one per detached thread) are again all printed on one line instead of one...
authorBart Van Assche <bvanassche@acm.org>
Thu, 13 Mar 2008 17:34:43 +0000 (17:34 +0000)
committerBart Van Assche <bvanassche@acm.org>
Thu, 13 Mar 2008 17:34:43 +0000 (17:34 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7669

exp-drd/tests/pth_detached.c
exp-drd/tests/pth_detached.stdout.exp
exp-drd/tests/pth_detached2.stdout.exp

index 721f4df8ac2315b2c9388a816eb54462c4bb0fd0..cbc6b6e37d2ea96524820d2741585a953cbf1f3a 100644 (file)
@@ -5,15 +5,15 @@
 
 #include <assert.h>
 #include <pthread.h>
+#include <semaphore.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include "../drd_clientreq.h"
 
 
-static int s_finished_count;
-static int s_set_thread_name;
-static pthread_mutex_t s_mutex;
+static int   s_set_thread_name;
+static sem_t s_sem;
 
 
 static void set_thread_name(const char* const fmt, const int arg)
@@ -29,26 +29,15 @@ static void set_thread_name(const char* const fmt, const int arg)
   }
 }
 
-void increment_finished_count()
+static void increment_finished_count()
 {
-  pthread_mutex_lock(&s_mutex);
-  s_finished_count++;
-  pthread_mutex_unlock(&s_mutex);
-}
-
-int get_finished_count()
-{
-  int result;
-  pthread_mutex_lock(&s_mutex);
-  result = s_finished_count;
-  pthread_mutex_unlock(&s_mutex);
-  return result;
+  sem_post(&s_sem);
 }
 
 static void* thread_func1(void* arg)
 {
   set_thread_name("thread_func1[%d]", *(int*)arg);
-  write(STDOUT_FILENO, ".\n", 2);
+  write(STDOUT_FILENO, ".", 1);
   increment_finished_count();
   return 0;
 }
@@ -57,7 +46,7 @@ static void* thread_func2(void* arg)
 {
   set_thread_name("thread_func2[%d]", *(int*)arg);
   pthread_detach(pthread_self());
-  write(STDOUT_FILENO, ".\n", 2);
+  write(STDOUT_FILENO, ".", 1);
   increment_finished_count();
   return 0;
 }
@@ -79,7 +68,7 @@ int main(int argc, char** argv)
   for (i = 0; i < count1 || i < count2; i++)
     thread_arg[i] = i;
 
-  pthread_mutex_init(&s_mutex, 0);
+  sem_init(&s_sem, 0, 0);
   
   pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -105,15 +94,14 @@ int main(int argc, char** argv)
   pthread_attr_destroy(&attr);
 
   // Wait until all detached threads have written their output to stdout.
-  while (get_finished_count() < count1 + count2)
+  for (i = 0; i < count1 + count2; i++)
   {
-    struct timespec delay = { 0, 1 * 1000 * 1000 };
-    nanosleep(&delay, 0);
+    sem_wait(&s_sem);
   }
 
-  printf("\n");
+  write(STDOUT_FILENO, "\n", 1);
 
-  pthread_mutex_destroy(&s_mutex);
+  sem_destroy(&s_sem);
 
   return 0;
 }
index 727e81ea6c9b3a27a19e05a534664ebc782bf99e..f3229c5b98768fac9af7b7ba56da9c071958d0f3 100644 (file)
@@ -1,3 +1 @@
-.
-.
-
+..
index b6c290864f5f06424ba62f116d92f79c1996eee8..01bfb0256c3fed5394ddfec32512b3bfdb516cc5 100644 (file)
@@ -1,21 +1 @@
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-.
-
+....................