39 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t2// RUN: %env_tsan_opts=flush_memory_ms=1:flush_symbolizer_ms=1:memory_limit_mb=1 not %run %t 2>&1 | FileCheck %s3#include "test.h"4 5long X, Y;6 7void *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 15int 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 // The race may not be detected since we are doing aggressive flushes33 // (if the state flush happens between racing accesses, tsan won't34 // detect the race). So return 1 to make the test deterministic.35 return 1;36}37 38// CHECK: DONE39