1// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=print_full_thread_history=true %deflake %run %t 2>&1 | FileCheck %s
2
3#include "test.h"
4
5int Global;
6
7void *Thread2(void *x) {
8 barrier_wait(barrier: &barrier);
9 Global++;
10 return NULL;
11}
12
13void *Thread3(void *x) {
14 Global--;
15 barrier_wait(barrier: &barrier);
16 return NULL;
17}
18
19void *Thread1(void *x) {
20 pthread_t t[2];
21 pthread_create(newthread: &t[0], NULL, start_routine: Thread2, NULL);
22 pthread_create(newthread: &t[1], NULL, start_routine: Thread3, NULL);
23 pthread_join(th: t[0], NULL);
24 pthread_join(th: t[1], NULL);
25 return NULL;
26}
27
28int main() {
29 barrier_init(barrier: &barrier, count: 2);
30 pthread_t t;
31 pthread_create(newthread: &t, NULL, start_routine: Thread1, NULL);
32 pthread_join(th: t, NULL);
33 return 0;
34}
35
36// CHECK: WARNING: ThreadSanitizer: data race
37// CHECK: Thread T2 {{.*}} created by thread T1 at
38// CHECK: Thread T3 {{.*}} created by thread T1 at:
39// CHECK: Thread T1 {{.*}} created by main thread at:
40// CHECK: SUMMARY: ThreadSanitizer: data race{{.*}}
41

source code of compiler-rt/test/tsan/print_full_thread_history.cpp