xref: /llvm-project/compiler-rt/test/tsan/print_full_thread_history.cpp (revision 1d4d2cceda82514f94d8128ad8404a08f74e7474)
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 
5 int Global;
6 
Thread2(void * x)7 void *Thread2(void *x) {
8   barrier_wait(&barrier);
9   Global++;
10   return NULL;
11 }
12 
Thread3(void * x)13 void *Thread3(void *x) {
14   Global--;
15   barrier_wait(&barrier);
16   return NULL;
17 }
18 
Thread1(void * x)19 void *Thread1(void *x) {
20   pthread_t t[2];
21   pthread_create(&t[0], NULL, Thread2, NULL);
22   pthread_create(&t[1], NULL, Thread3, NULL);
23   pthread_join(t[0], NULL);
24   pthread_join(t[1], NULL);
25   return NULL;
26 }
27 
main()28 int main() {
29   barrier_init(&barrier, 2);
30   pthread_t t;
31   pthread_create(&t, NULL, Thread1, NULL);
32   pthread_join(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