Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / race_on_barrier2.c
blob49adb62312309c104578ef438b2bcf5e6066bd9a
1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
3 // pthread barriers are not available on OS X
4 // UNSUPPORTED: darwin
6 #include <pthread.h>
7 #include <stdio.h>
8 #include <stddef.h>
9 #include <unistd.h>
11 pthread_barrier_t B;
12 int Global;
14 void *Thread1(void *x) {
15 if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD)
16 pthread_barrier_destroy(&B);
17 return NULL;
20 void *Thread2(void *x) {
21 if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD)
22 pthread_barrier_destroy(&B);
23 return NULL;
26 int 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;
35 // CHECK: WARNING: ThreadSanitizer: data race