]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd/tests/pth_barrier: Reduce stack usage
authorBart Van Assche <bvanassche@acm.org>
Fri, 12 Aug 2011 15:21:31 +0000 (15:21 +0000)
committerBart Van Assche <bvanassche@acm.org>
Fri, 12 Aug 2011 15:21:31 +0000 (15:21 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11968

drd/tests/pth_barrier.c

index 7bca33a5b65a47e24d4fc6db978dc3558e814a9e..0aea190289553d59ec30abbb4cefc401277c891a 100644 (file)
 /***********************/
 
 #include <assert.h>
+#include <limits.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <errno.h>
 
 
 /*********************/
@@ -65,7 +65,8 @@ static void* threadfunc(struct threadinfo* p)
 /** Actual test, consisting of nthread threads. */
 static void barriers_and_races(const int nthread, const int iterations)
 {
-  int i;
+  int i, res;
+  pthread_attr_t attr;
   struct threadinfo* t;
   pthread_barrier_t b;
   int* array;
@@ -78,18 +79,25 @@ static void barriers_and_races(const int nthread, const int iterations)
 
   pthread_barrier_init(&b, 0, nthread);
 
+  pthread_attr_init(&attr);
+  res = pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + 4096);
+  assert(res == 0);
+
   for (i = 0; i < nthread; i++)
   {
     t[i].b = &b;
     t[i].array = array;
     t[i].iterations = iterations;
-    if (pthread_create(&t[i].tid, 0, (void*(*)(void*))threadfunc, &t[i])) {
+    res = pthread_create(&t[i].tid, &attr, (void*(*)(void*))threadfunc, &t[i]);
+    if (res != 0) {
       fprintf(stderr, "Could not create thread #%d (of %d): %s\n",
-              i, nthread, strerror(errno));
+              i, nthread, strerror(res));
       exit(1);
     }
   }
 
+  pthread_attr_destroy(&attr);
+
   for (i = 0; i < nthread; i++)
   {
     pthread_join(t[i].tid, 0);