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