1// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2
3// pthread barriers are not available on OS X
4// UNSUPPORTED: darwin
5
6#include "test.h"
7
8pthread_barrier_t B;
9int Global;
10
11void *Thread1(void *x) {
12 pthread_barrier_init(barrier: &B, attr: 0, count: 2);
13 barrier_wait(barrier: &barrier);
14 pthread_barrier_wait(barrier: &B);
15 return NULL;
16}
17
18void *Thread2(void *x) {
19 barrier_wait(barrier: &barrier);
20 pthread_barrier_wait(barrier: &B);
21 return NULL;
22}
23
24int main() {
25 barrier_init(barrier: &barrier, count: 2);
26 pthread_t t;
27 pthread_create(newthread: &t, NULL, start_routine: Thread1, NULL);
28 Thread2(x: 0);
29 pthread_join(th: t, NULL);
30 pthread_barrier_destroy(barrier: &B);
31 return 0;
32}
33
34// CHECK: WARNING: ThreadSanitizer: data race
35

source code of compiler-rt/test/tsan/race_on_barrier.c