1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
3
4char s[] = "abracadabra";
5
6void *Thread0(void *p) {
7 fputs(s: s, stdout);
8 barrier_wait(barrier: &barrier);
9 return 0;
10}
11
12void *Thread1(void *p) {
13 barrier_wait(barrier: &barrier);
14 s[3] = 'z';
15 return 0;
16}
17
18int main() {
19 barrier_init(barrier: &barrier, count: 2);
20 pthread_t th[2];
21 pthread_create(newthread: &th[0], attr: 0, start_routine: Thread0, arg: 0);
22 pthread_create(newthread: &th[1], attr: 0, start_routine: Thread1, arg: 0);
23 pthread_join(th: th[0], thread_return: 0);
24 pthread_join(th: th[1], thread_return: 0);
25 fprintf(stderr, format: "DONE");
26}
27
28// CHECK: WARNING: ThreadSanitizer: data race
29// CHECK: DONE
30

source code of compiler-rt/test/tsan/race_on_fputs.cpp