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 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 2 | |
| 3 | // pthread barriers are not available on OS X |
| 4 | // UNSUPPORTED: darwin |
| 5 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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(&B) == PTHREAD_BARRIER_SERIAL_THREAD) |
| 16 | pthread_barrier_destroy(&B); |
| 17 | return NULL; |
| 18 | } |
| 19 | |
| 20 | void *Thread2(void *x) { |
| 21 | if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD) |
| 22 | pthread_barrier_destroy(&B); |
| 23 | return NULL; |
| 24 | } |
| 25 | |
| 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; |
| 33 | } |
| 34 | |
| 35 | // CHECK: WARNING: ThreadSanitizer: data race |