1// RUN: %clangxx_tsan -O1 --std=c++11 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2#include "custom_mutex.h"
3
4// Test that Broadcast does not induce parasitic synchronization.
5
6Mutex mu(true, 0);
7long data;
8
9void *thr(void *arg) {
10 barrier_wait(&barrier);
11 mu.Lock();
12 data++;
13 mu.Unlock();
14 data++;
15 mu.Broadcast();
16 return 0;
17}
18
19int main() {
20 barrier_init(&barrier, 2);
21 pthread_t th;
22 pthread_create(&th, 0, thr, 0);
23 mu.Lock();
24 barrier_wait(&barrier);
25 while (data == 0)
26 mu.Wait();
27 mu.Unlock();
28 pthread_join(th, 0);
29 fprintf(stderr, "DONE\n");
30 return 0;
31}
32
33// CHECK: ThreadSanitizer: data race
34// CHECK: DONE
35