Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 2 | #include <pthread.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stddef.h> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | pthread_barrier_t B; |
| 8 | int Global; |
| 9 | |
| 10 | void *Thread1(void *x) { |
| 11 | if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD) |
| 12 | pthread_barrier_destroy(&B); |
| 13 | return NULL; |
| 14 | } |
| 15 | |
| 16 | void *Thread2(void *x) { |
| 17 | if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD) |
| 18 | pthread_barrier_destroy(&B); |
| 19 | return NULL; |
| 20 | } |
| 21 | |
| 22 | int main() { |
| 23 | pthread_barrier_init(&B, 0, 2); |
| 24 | pthread_t t; |
| 25 | pthread_create(&t, NULL, Thread1, NULL); |
| 26 | Thread2(0); |
| 27 | pthread_join(t, NULL); |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | // CHECK: WARNING: ThreadSanitizer: data race |