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 not %run %t 2>&1 | FileCheck %s
7 void *Thread(void *arg
) {
8 __atomic_fetch_add(&X
, 1, __ATOMIC_SEQ_CST
);
9 barrier_wait(&barrier
);
10 barrier_wait(&barrier
);
16 __tsan_flush_memory();
17 barrier_init(&barrier
, 2);
18 __atomic_fetch_add(&X
, 1, __ATOMIC_SEQ_CST
);
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.
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.
30 __tsan_flush_memory();
31 fprintf(stderr
, "DONE\n");
32 // The race may not be detected since we are doing aggressive flushes
33 // (if the state flush happens between racing accesses, tsan won't
34 // detect the race). So return 1 to make the test deterministic.