1 // RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s 2 // RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s 3 #include "test.h" 4 5 volatile int X; 6 volatile int N; 7 void (*volatile F)(); 8 foo()9static void foo() { 10 if (--N == 0) 11 X = 42; 12 else 13 F(); 14 } 15 Thread(void * p)16void *Thread(void *p) { 17 #ifdef ORDER1 18 barrier_wait(&barrier); 19 #endif 20 F(); 21 #ifdef ORDER2 22 barrier_wait(&barrier); 23 #endif 24 return 0; 25 } 26 main()27int main() { 28 barrier_init(&barrier, 2); 29 N = 50000; 30 F = foo; 31 pthread_t t; 32 pthread_attr_t a; 33 pthread_attr_init(&a); 34 pthread_attr_setstacksize(&a, N * 256 + (1 << 20)); 35 pthread_create(&t, &a, Thread, 0); 36 #ifdef ORDER2 37 barrier_wait(&barrier); 38 #endif 39 X = 43; 40 #ifdef ORDER1 41 barrier_wait(&barrier); 42 #endif 43 44 pthread_join(t, 0); 45 } 46 47 // CHECK: WARNING: ThreadSanitizer: data race 48 // CHECK: #100 foo 49 // We must output suffucuently large stack (at least 100 frames) 50 51