2 * Test program that triggers a race between pthread_barrier_wait() and
3 * pthread_barrier_destroy(): proper synchronization is missing between
4 * the pthread_barrier_wait() and the pthread_barrier_destroy() calls. This
5 * test program is based on the example that was posted on February 5, 2009 by
6 * Christoph Bartoschek on the valgrind-users mailing list. Redistribution of
7 * the source code below is permitted under the GPLv2 license.
9 * See also http://article.gmane.org/gmane.comp.debugging.valgrind/8945/match=pthread_barrier_wait
19 static pthread_barrier_t
* barrier
;
22 static void* thread(void* arg
)
24 pthread_barrier_wait(barrier
);
32 barrier
= (pthread_barrier_t
*) malloc(sizeof(*barrier
));
33 pthread_barrier_init(barrier
, NULL
, 2);
35 pthread_create(&tid
, NULL
, thread
, NULL
);
37 pthread_barrier_wait(barrier
);
39 * The sleep() call below ensures that the pthread_barrier_destroy() call
40 * happens after the created thread has returned from pthread_barrier_wait().
43 pthread_barrier_destroy(barrier
);
46 pthread_join(tid
, NULL
);