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 <pthread.h>
7#include <stdio.h>
8#include <stddef.h>
9#include <unistd.h>
10
11pthread_barrier_t B;
12int Global;
13
14void *Thread1(void *x) {
15 if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD)
16 pthread_barrier_destroy(&B);
17 return NULL;
18}
19
20void *Thread2(void *x) {
21 if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD)
22 pthread_barrier_destroy(&B);
23 return NULL;
24}
25
26int main() {
27 pthread_barrier_init(&B, 0, 2);
28 pthread_t t;
29 pthread_create(&t, NULL, Thread1, NULL);
30 Thread2(0);
31 pthread_join(t, NULL);
32 return 0;
33}
34
35// CHECK: WARNING: ThreadSanitizer: data race
36