1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
7 void *Thread1(void *x
) {
8 barrier_wait(&barrier
);
9 pthread_mutex_lock(&mtx
);
11 pthread_mutex_unlock(&mtx
);
15 void *Thread2(void *x
) {
17 barrier_wait(&barrier
);
22 barrier_init(&barrier
, 2);
23 // CHECK: WARNING: ThreadSanitizer: data race
24 // CHECK: Write of size 4 at {{.*}} by thread T1
25 // CHECK: (mutexes: write [[M1:M[0-9]+]]):
26 // CHECK: Previous write of size 4 at {{.*}} by thread T2:
27 // CHECK: Mutex [[M1]] (0x{{.*}}) created at:
28 // CHECK: #0 pthread_mutex_init
29 // CHECK: #1 main {{.*}}mutexset1.cpp:[[@LINE+1]]
30 pthread_mutex_init(&mtx
, 0);
32 pthread_create(&t
[0], NULL
, Thread1
, NULL
);
33 pthread_create(&t
[1], NULL
, Thread2
, NULL
);
34 pthread_join(t
[0], NULL
);
35 pthread_join(t
[1], NULL
);
36 pthread_mutex_destroy(&mtx
);