2 * Creates 8 threads. The fifth one (counting the main thread as well)
13 #define NEVERENDING_SLEEP 10000
15 static pthread_barrier_t barrier
;
17 static void *thread_func2(void *arg
) {
18 pthread_barrier_wait(&barrier
);
19 sleep(NEVERENDING_SLEEP
);
23 static void *thread_func3(void *arg
) {
24 pthread_barrier_wait(&barrier
);
25 sleep(NEVERENDING_SLEEP
);
29 static void *thread_func4(void *arg
) {
30 pthread_barrier_wait(&barrier
);
31 sleep(NEVERENDING_SLEEP
);
35 static void *thread_func5(void *arg
) {
36 pthread_barrier_wait(&barrier
);
39 char *x
= (char *) 0x1;
44 static void *thread_func6(void *arg
) {
45 pthread_barrier_wait(&barrier
);
46 sleep(NEVERENDING_SLEEP
);
50 static void *thread_func7(void *arg
) {
51 pthread_barrier_wait(&barrier
);
52 sleep(NEVERENDING_SLEEP
);
56 static void *thread_func8(void *arg
) {
57 pthread_barrier_wait(&barrier
);
58 sleep(NEVERENDING_SLEEP
);
62 static void *thread_func9(void *arg
) {
63 pthread_barrier_wait(&barrier
);
64 sleep(NEVERENDING_SLEEP
);
68 static void create_thread(void *(*thread_func
)(void *))
72 int ret
= pthread_create(&thread
, NULL
, thread_func
, NULL
);
74 fprintf(stderr
, "pthread_create: %s (%d)\n", strerror(ret
), ret
);
79 int main(int argc
, const char *argv
[])
81 int ret
= pthread_barrier_init(&barrier
, NULL
, 9);
83 fprintf(stderr
, "pthread_barrier_init: %s (%d)\n",
88 create_thread(thread_func2
);
89 create_thread(thread_func3
);
90 create_thread(thread_func4
);
91 create_thread(thread_func5
);
92 create_thread(thread_func6
);
93 create_thread(thread_func7
);
94 create_thread(thread_func8
);
95 create_thread(thread_func9
);
96 pthread_barrier_wait(&barrier
);
98 sleep(NEVERENDING_SLEEP
);