Add support for landlock_create_ruleset (444), landlock_add_rule (445) and landlock_r...
[valgrind.git] / drd / tests / pth_create_chain.c
blobadd1b33f0a931850f49c9ccc814c7c4cd2aeded8
1 // Create threads in such a way that there is a realistic chance that the
2 // parent thread finishes before the created thread finishes.
5 #include <assert.h>
6 #include <limits.h> /* PTHREAD_STACK_MIN */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <pthread.h>
10 #include "config.h"
13 static pthread_t s_thread[1000];
14 static int s_arg[1000];
16 static void* thread_func(void* p)
18 int thread_count = *(int*)(p);
19 pthread_attr_t attr;
21 if (thread_count > 0)
23 thread_count--;
24 // std::cout << "create " << thread_count << std::endl;
25 s_arg[thread_count] = thread_count;
26 pthread_attr_init(&attr);
27 #if !defined(VGO_freebsd)
28 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
29 #endif
30 pthread_create(&s_thread[thread_count], &attr, thread_func,
31 &s_arg[thread_count]);
32 pthread_attr_destroy(&attr);
33 #if 0
34 std::cout << "created " << thread_count << "(" << s_thread[thread_count]
35 << ")" << std::endl;
36 #endif
38 return 0;
41 int main(int argc, char** argv)
43 pthread_attr_t attr;
44 unsigned thread_count;
45 int i;
47 thread_count = argc > 1 ? atoi(argv[1]) : 50;
48 assert(thread_count <= sizeof(s_thread) / sizeof(s_thread[0]));
49 assert(thread_count >= 1);
50 thread_count--;
51 // std::cout << "create " << thread_count << std::endl;
52 pthread_attr_init(&attr);
53 #if !defined(VGO_freebsd)
54 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
55 #endif
56 pthread_create(&s_thread[thread_count], &attr, thread_func,
57 &thread_count);
58 pthread_attr_destroy(&attr);
59 #if 0
60 std::cout << "created " << thread_count << "(" << s_thread[thread_count]
61 << ")" << std::endl;
62 #endif
63 for (i = thread_count; i >= 0; i--)
65 // std::cout << "join " << i << "(" << s_thread[i] << ")" << std::endl;
66 pthread_join(s_thread[i], 0);
68 return 0;