[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / tsan / mutexset1.cc
blob49607d7a293f3d61938de597180e1a7955d76625
1 // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <unistd.h>
6 int Global;
7 pthread_mutex_t mtx;
9 void *Thread1(void *x) {
10 sleep(1);
11 pthread_mutex_lock(&mtx);
12 Global++;
13 pthread_mutex_unlock(&mtx);
14 return NULL;
17 void *Thread2(void *x) {
18 Global--;
19 return NULL;
22 int main() {
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.cc:[[@LINE+1]]
30 pthread_mutex_init(&mtx, 0);
31 pthread_t t[2];
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);