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: &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: &barrier, count: 2);
21 pthread_t th;
22 pthread_create(newthread: &th, attr: 0, start_routine: thr, arg: 0);
23 mu.Lock();
24 barrier_wait(barrier: &barrier);
25 while (data == 0)
26 mu.Wait();
27 mu.Unlock();
28 pthread_join(th: th, thread_return: 0);
29 fprintf(stderr, format: "DONE\n");
30 return 0;
31}
32
33// CHECK: ThreadSanitizer: data race
34// CHECK: DONE
35

source code of compiler-rt/test/tsan/custom_mutex2.cpp