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 | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 6 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 7 | |
| 8 | pthread_barrier_t B; |
| 9 | int Global; |
| 10 | |
| 11 | void *Thread1(void *x) { |
| 12 | pthread_barrier_init(&B, 0, 2); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 13 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 14 | pthread_barrier_wait(&B); |
| 15 | return NULL; |
| 16 | } |
| 17 | |
| 18 | void *Thread2(void *x) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 19 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 20 | pthread_barrier_wait(&B); |
| 21 | return NULL; |
| 22 | } |
| 23 | |
| 24 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 25 | barrier_init(&barrier, 2); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 26 | pthread_t t; |
| 27 | pthread_create(&t, NULL, Thread1, NULL); |
| 28 | Thread2(0); |
| 29 | pthread_join(t, NULL); |
| 30 | pthread_barrier_destroy(&B); |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | // CHECK: WARNING: ThreadSanitizer: data race |