Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / custom_mutex2.cpp
blobd4aca7e038cfa833cf65a22a790781904296c6aa
1 // RUN: %clangxx_tsan -O1 --std=c++11 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2 #include "custom_mutex.h"
4 // Test that Broadcast does not induce parasitic synchronization.
6 Mutex mu(true, 0);
7 long data;
9 void *thr(void *arg) {
10 barrier_wait(&barrier);
11 mu.Lock();
12 data++;
13 mu.Unlock();
14 data++;
15 mu.Broadcast();
16 return 0;
19 int 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;
33 // CHECK: ThreadSanitizer: data race
34 // CHECK: DONE