1 /* { dg-shouldfail "tsan" } */
2 /* { dg-additional-options "-ldl" } */
3 /* { dg-output "ThreadSanitizer: data race.*" } */
4 /* { dg-output "pthread_cond_signal.*" } */
5 
6 #include <pthread.h>
7 #include "tsan_barrier.h"
8 
9 static pthread_barrier_t barrier;
10 
11 struct Ctx {
12   pthread_mutex_t m;
13   pthread_cond_t c;
14   bool done;
15 };
16 
thr(void * p)17 void *thr(void *p) {
18   Ctx *c = (Ctx*)p;
19   pthread_mutex_lock(&c->m);
20   c->done = true;
21   pthread_mutex_unlock(&c->m);
22   pthread_cond_signal(&c->c);
23   barrier_wait(&barrier);
24   return 0;
25 }
26 
main()27 int main() {
28   barrier_init(&barrier, 2);
29   Ctx *c = new Ctx();
30   pthread_mutex_init(&c->m, 0);
31   pthread_cond_init(&c->c, 0);
32   pthread_t th;
33   pthread_create(&th, 0, thr, c);
34   pthread_mutex_lock(&c->m);
35   while (!c->done)
36     pthread_cond_wait(&c->c, &c->m);
37   pthread_mutex_unlock(&c->m);
38   barrier_wait(&barrier);
39   delete c;
40   pthread_join(th, 0);
41 }
42