]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd/tests/pth_detached.c: eliminated thread_arg[] array and introduced PTHREAD_STACK_MIN.
authorBart Van Assche <bvanassche@acm.org>
Tue, 17 May 2011 16:45:08 +0000 (16:45 +0000)
committerBart Van Assche <bvanassche@acm.org>
Tue, 17 May 2011 16:45:08 +0000 (16:45 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11769

drd/tests/pth_detached.c

index b41a39f00de3548a5363db41bf112b18a6e5075c..88d22d9b38a1b54a2e5cdba2570435b451a94cad 100644 (file)
@@ -1,6 +1,7 @@
 /* Test whether detached threads are handled properly. */
 
 #include <assert.h>
+#include <limits.h>  /* PTHREAD_STACK_MIN */
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -37,14 +38,10 @@ int main(int argc, char** argv)
 {
   const int count1 = argc > 1 ? atoi(argv[1]) : 100;
   const int count2 = argc > 2 ? atoi(argv[2]) : 100;
-  int thread_arg[count1 > count2 ? count1 : count2];
   int i;
   int detachstate;
   pthread_attr_t attr;
 
-  for (i = 0; i < count1 || i < count2; i++)
-    thread_arg[i] = i;
-
   pthread_mutex_init(&s_mutex, 0);
   pthread_cond_init(&s_cond, 0);
 
@@ -52,13 +49,13 @@ int main(int argc, char** argv)
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
   assert(pthread_attr_getdetachstate(&attr, &detachstate) == 0);
   assert(detachstate == PTHREAD_CREATE_DETACHED);
-  pthread_attr_setstacksize(&attr, 16384);
+  pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + 4096);
   // Create count1 detached threads by setting the "detached" property via
   // thread attributes.
   for (i = 0; i < count1; i++)
   {
     pthread_t thread;
-    pthread_create(&thread, &attr, thread_func1, &thread_arg[i]);
+    pthread_create(&thread, &attr, thread_func1, NULL);
   }
   // Create count2 detached threads by letting the threads detach themselves.
   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
@@ -67,7 +64,7 @@ int main(int argc, char** argv)
   for (i = 0; i < count2; i++)
   {
     pthread_t thread;
-    pthread_create(&thread, &attr, thread_func2, &thread_arg[i]);
+    pthread_create(&thread, &attr, thread_func2, NULL);
   }
   pthread_attr_destroy(&attr);