Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / mutexset7.cpp
blob5b4c7b9bb38cb77b7768cd6153bfa97bf5d31f72
1 // RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \
2 // RUN: %deflake %run %t | FileCheck %s
3 #include "test.h"
5 int Global;
6 __thread int huge[1024*1024];
8 void *Thread1(void *x) {
9 barrier_wait(&barrier);
10 Global++;
11 return NULL;
14 void *Thread2(void *x) {
15 pthread_mutex_t *mtx = new pthread_mutex_t;
16 pthread_mutex_init(mtx, 0);
17 pthread_mutex_lock(mtx);
18 Global--;
19 pthread_mutex_unlock(mtx);
20 pthread_mutex_destroy(mtx);
21 delete mtx;
22 barrier_wait(&barrier);
23 return NULL;
26 int main() {
27 barrier_init(&barrier, 2);
28 pthread_t t[2];
29 pthread_create(&t[0], NULL, Thread1, NULL);
30 pthread_create(&t[1], NULL, Thread2, NULL);
31 pthread_join(t[0], NULL);
32 pthread_join(t[1], NULL);
35 // CHECK: WARNING: ThreadSanitizer: data race
36 // CHECK: Write of size 4 at {{.*}} by thread T1:
37 // CHECK: Previous write of size 4 at {{.*}} by thread T2
38 // CHECK: (mutexes: write [[M1:M[0-9]+]]):
39 // CHECK: Mutex [[M1]] (0x{{.*}}) created at:
40 // CHECK: #0 pthread_mutex_init
41 // CHECK: #1 Thread2