2 * Test program that triggers pthread_barrier_wait() where each
3 * pthread_barrier_wait() call is invoked by another thread. This is the only
4 * test program that triggers the code guarded by if (q->thread_finished) in
5 * DRD_(barrier_pre_wait)().
16 static pthread_barrier_t
* s_barrier
;
18 static void* thread(void* arg
)
20 write(STDOUT_FILENO
, ".", 1);
21 pthread_barrier_wait(s_barrier
);
25 int main(int argc
, char** argv
)
28 int barriers
= argc
> 1 ? atoi(argv
[1]) : 20;
29 int barrier_participants
= 2;
30 int thread_count
= barriers
* barrier_participants
;
33 s_barrier
= malloc(sizeof(*s_barrier
));
34 res
= pthread_barrier_init(s_barrier
, NULL
, barrier_participants
);
37 tid
= malloc(thread_count
* sizeof(*tid
));
39 for (i
= 0; i
< thread_count
; i
++) {
40 res
= pthread_create(&tid
[i
], NULL
, thread
, NULL
);
43 for (i
= 0; i
< thread_count
; i
++) {
44 res
= pthread_join(tid
[i
], NULL
);
49 res
= pthread_barrier_destroy(s_barrier
);
54 write(STDOUT_FILENO
, "\n", 1);
55 fprintf(stderr
, "Done.\n");