1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 // This test fails on powerpc64 (VMA=46).
3 // The size of the write reported by Tsan for T1 is 8 instead of 1.
4 // XFAIL: powerpc64
5 #include "test.h"
6
7 pthread_mutex_t Mtx;
8 int Global;
9
Thread1(void * x)10 void *Thread1(void *x) {
11 pthread_mutex_init(&Mtx, 0);
12 pthread_mutex_lock(&Mtx);
13 Global = 42;
14 pthread_mutex_unlock(&Mtx);
15 barrier_wait(&barrier);
16 return NULL;
17 }
18
Thread2(void * x)19 void *Thread2(void *x) {
20 barrier_wait(&barrier);
21 pthread_mutex_lock(&Mtx);
22 Global = 43;
23 pthread_mutex_unlock(&Mtx);
24 return NULL;
25 }
26
main()27 int main() {
28 barrier_init(&barrier, 2);
29 pthread_t t[2];
30 pthread_create(&t[0], NULL, Thread1, NULL);
31 pthread_create(&t[1], NULL, Thread2, NULL);
32 pthread_join(t[0], NULL);
33 pthread_join(t[1], NULL);
34 pthread_mutex_destroy(&Mtx);
35 return 0;
36 }
37
38 // CHECK: WARNING: ThreadSanitizer: data race
39 // CHECK-NEXT: Atomic read of size 1 at {{.*}} by thread T2:
40 // CHECK-NEXT: #0 pthread_mutex_lock
41 // CHECK-NEXT: #1 Thread2{{.*}} {{.*}}race_on_mutex.c:21{{(:3)?}} ({{.*}})
42 // CHECK: Previous write of size 1 at {{.*}} by thread T1:
43 // CHECK-NEXT: #0 pthread_mutex_init {{.*}} ({{.*}})
44 // CHECK-NEXT: #1 Thread1{{.*}} {{.*}}race_on_mutex.c:11{{(:3)?}} ({{.*}})
45