Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / custom_mutex1.cpp
blobc9324e5640be0e84247e58ee3c7a92cbb653de1a
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 failed TryLock does not induce parasitic synchronization.
6 Mutex mu(true, 0);
7 long data;
9 void *thr(void *arg) {
10 mu.Lock();
11 data++;
12 mu.Unlock();
13 mu.Lock();
14 barrier_wait(&barrier);
15 barrier_wait(&barrier);
16 mu.Unlock();
17 return 0;
20 int main() {
21 barrier_init(&barrier, 2);
22 pthread_t th;
23 pthread_create(&th, 0, thr, 0);
24 barrier_wait(&barrier);
25 if (mu.TryLock()) {
26 fprintf(stderr, "TryLock succeeded, should not\n");
27 exit(0);
29 data++;
30 barrier_wait(&barrier);
31 pthread_join(th, 0);
32 fprintf(stderr, "DONE\n");
33 return 0;
36 // CHECK: ThreadSanitizer: data race
37 // CHECK-NEXT: Write of size 8 at {{.*}} by main thread:
38 // CHECK-NEXT: #0 main {{.*}}custom_mutex1.cpp:29
39 // CHECK: DONE