annotate compiler-rt/test/tsan/mutexset8.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
anatofuz
parents:
diff changeset
2 #include "test.h"
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 int Global;
anatofuz
parents:
diff changeset
5 pthread_mutex_t *mtx;
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 void *Thread1(void *x) {
anatofuz
parents:
diff changeset
8 barrier_wait(&barrier);
anatofuz
parents:
diff changeset
9 pthread_mutex_lock(mtx);
anatofuz
parents:
diff changeset
10 Global++;
anatofuz
parents:
diff changeset
11 pthread_mutex_unlock(mtx);
anatofuz
parents:
diff changeset
12 return NULL;
anatofuz
parents:
diff changeset
13 }
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 void *Thread2(void *x) {
anatofuz
parents:
diff changeset
16 Global--;
anatofuz
parents:
diff changeset
17 barrier_wait(&barrier);
anatofuz
parents:
diff changeset
18 return NULL;
anatofuz
parents:
diff changeset
19 }
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 int main() {
anatofuz
parents:
diff changeset
22 barrier_init(&barrier, 2);
anatofuz
parents:
diff changeset
23 // CHECK: WARNING: ThreadSanitizer: data race
anatofuz
parents:
diff changeset
24 // CHECK: Write of size 4 at {{.*}} by thread T1
anatofuz
parents:
diff changeset
25 // CHECK: (mutexes: write [[M1:M[0-9]+]]):
anatofuz
parents:
diff changeset
26 // CHECK: Previous write of size 4 at {{.*}} by thread T2:
anatofuz
parents:
diff changeset
27 // CHECK: Mutex [[M1]] (0x{{.*}}) created at:
anatofuz
parents:
diff changeset
28 // CHECK: #0 pthread_mutex_init
anatofuz
parents:
diff changeset
29 // CHECK: #1 main {{.*}}mutexset8.cpp
anatofuz
parents:
diff changeset
30 mtx = new pthread_mutex_t;
anatofuz
parents:
diff changeset
31 pthread_mutex_init(mtx, 0);
anatofuz
parents:
diff changeset
32 pthread_t t[2];
anatofuz
parents:
diff changeset
33 pthread_create(&t[0], NULL, Thread1, NULL);
anatofuz
parents:
diff changeset
34 pthread_create(&t[1], NULL, Thread2, NULL);
anatofuz
parents:
diff changeset
35 pthread_join(t[0], NULL);
anatofuz
parents:
diff changeset
36 pthread_join(t[1], NULL);
anatofuz
parents:
diff changeset
37 pthread_mutex_destroy(mtx);
anatofuz
parents:
diff changeset
38 delete mtx;
anatofuz
parents:
diff changeset
39 }