Check some known PATHs for mpicc in configure.
[valgrind.git] / drd / tests / pth_barrier_race.c
blob2255a0e71e55931d220d1c61f9c1aada3d6e6084
1 /*
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
13 #define _GNU_SOURCE
15 #include <pthread.h>
16 #include <stdlib.h>
17 #include <unistd.h>
19 static pthread_barrier_t* barrier;
22 static void* thread(void* arg)
24 pthread_barrier_wait(barrier);
25 return NULL;
28 int main()
30 pthread_t tid;
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().
42 sleep(1);
43 pthread_barrier_destroy(barrier);
44 free(barrier);
46 pthread_join(tid, NULL);
47 return 0;