Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / mutexset4.cpp
blob417efbd0d3c1582858caacf5d88436b812caadcf
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "test.h"
4 int Global;
5 pthread_mutex_t mtx1;
6 pthread_mutex_t mtx2;
8 void *Thread1(void *x) {
9 pthread_mutex_lock(&mtx1);
10 pthread_mutex_lock(&mtx2);
11 Global++;
12 pthread_mutex_unlock(&mtx2);
13 pthread_mutex_unlock(&mtx1);
14 barrier_wait(&barrier);
15 return NULL;
18 void *Thread2(void *x) {
19 barrier_wait(&barrier);
20 Global--;
21 return NULL;
24 int main() {
25 barrier_init(&barrier, 2);
26 // CHECK: WARNING: ThreadSanitizer: data race
27 // CHECK: Write of size 4 at {{.*}} by thread T2:
28 // CHECK: Previous write of size 4 at {{.*}} by thread T1
29 // CHECK: (mutexes: write [[M1:M[0-9]+]], write [[M2:M[0-9]+]]):
30 // CHECK: Mutex [[M1]] (0x{{.*}}) created at:
31 // CHECK: #0 pthread_mutex_init
32 // CHECK: #1 main {{.*}}mutexset4.cpp:[[@LINE+4]]
33 // CHECK: Mutex [[M2]] (0x{{.*}}) created at:
34 // CHECK: #0 pthread_mutex_init
35 // CHECK: #1 main {{.*}}mutexset4.cpp:[[@LINE+2]]
36 pthread_mutex_init(&mtx1, 0);
37 pthread_mutex_init(&mtx2, 0);
38 pthread_t t[2];
39 pthread_create(&t[0], NULL, Thread1, NULL);
40 pthread_create(&t[1], NULL, Thread2, NULL);
41 pthread_join(t[0], NULL);
42 pthread_join(t[1], NULL);
43 pthread_mutex_destroy(&mtx1);
44 pthread_mutex_destroy(&mtx2);