1 // RUN: %clangxx_tsan -O1 %s -o %t 2 // RUN: %env_tsan_opts=flush_memory_ms=1:flush_symbolizer_ms=1:memory_limit_mb=1 %deflake %run %t | FileCheck %s 3 #include "test.h" 4 5 long X, Y; 6 7 void *Thread(void *arg) { 8 __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST); 9 barrier_wait(&barrier); 10 barrier_wait(&barrier); 11 Y = 1; 12 return &Y; 13 } 14 15 int main() { 16 __tsan_flush_memory(); 17 barrier_init(&barrier, 2); 18 __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST); 19 pthread_t t; 20 pthread_create(&t, NULL, Thread, NULL); 21 barrier_wait(&barrier); 22 __tsan_flush_memory(); 23 // Trigger a race to test flushing of the symbolizer cache. 24 Y = 2; 25 barrier_wait(&barrier); 26 pthread_join(t, NULL); 27 __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST); 28 // Background runtime thread should do some flushes meanwhile. 29 sleep(2); 30 __tsan_flush_memory(); 31 fprintf(stderr, "DONE\n"); 32 return 0; 33 } 34 35 // CHECK: WARNING: ThreadSanitizer: data race 36 // CHECK: DONE 37