]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Check return code of pthread_create and bail out if
authorFlorian Krohm <florian@eich-krohm.de>
Fri, 12 Aug 2011 15:07:10 +0000 (15:07 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Fri, 12 Aug 2011 15:07:10 +0000 (15:07 +0000)
the function failed. This helps on systems which don't
have lots of memory.
Suggested by Christian Borntraeger.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11967

drd/tests/pth_barrier.c

index e0b40a7a134bc1613f2fe2d6aa9358ba6d863bad..7bca33a5b65a47e24d4fc6db978dc3558e814a9e 100644 (file)
@@ -13,6 +13,8 @@
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
+#include <errno.h>
 
 
 /*********************/
@@ -81,7 +83,11 @@ static void barriers_and_races(const int nthread, const int iterations)
     t[i].b = &b;
     t[i].array = array;
     t[i].iterations = iterations;
-    pthread_create(&t[i].tid, 0, (void*(*)(void*))threadfunc, &t[i]);
+    if (pthread_create(&t[i].tid, 0, (void*(*)(void*))threadfunc, &t[i])) {
+      fprintf(stderr, "Could not create thread #%d (of %d): %s\n",
+              i, nthread, strerror(errno));
+      exit(1);
+    }
   }
 
   for (i = 0; i < nthread; i++)