1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
7 void *Thread2(void *x
) {
8 barrier_wait(&barrier
);
9 // CHECK: WARNING: ThreadSanitizer: data race
10 // CHECK-NEXT: Atomic read of size 1 at {{.*}} by thread T2:
11 // CHECK-NEXT: #0 pthread_mutex_lock
12 // CHECK-NEXT: #1 Thread2{{.*}} {{.*}}race_on_mutex.c:[[@LINE+1]]{{(:3)?}} ({{.*}})
13 pthread_mutex_lock(&Mtx
);
15 pthread_mutex_unlock(&Mtx
);
19 void *Thread1(void *x
) {
20 // CHECK: Previous write of size {{[0-9]+}} at {{.*}} by thread T1:
21 // CHECK: #{{[0-9]+}} {{.*}}pthread_mutex_init {{.*}} ({{.*}})
22 // CHECK-NEXT: #{{[0-9]+}} Thread1{{.*}} {{.*}}race_on_mutex.c:[[@LINE+1]]{{(:3)?}} ({{.*}})
23 pthread_mutex_init(&Mtx
, 0);
24 pthread_mutex_lock(&Mtx
);
26 pthread_mutex_unlock(&Mtx
);
27 barrier_wait(&barrier
);
32 barrier_init(&barrier
, 2);
34 pthread_create(&t
[0], NULL
, Thread1
, NULL
);
35 pthread_create(&t
[1], NULL
, Thread2
, NULL
);
36 pthread_join(t
[0], NULL
);
37 pthread_join(t
[1], NULL
);
38 pthread_mutex_destroy(&Mtx
);