Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" %deflake %run %t | FileCheck %s |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 2 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 3 | |
| 4 | int X; |
| 5 | |
| 6 | void *Thread(void *x) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 7 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 8 | X = 42; |
| 9 | return 0; |
| 10 | } |
| 11 | |
| 12 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 13 | barrier_init(&barrier, 2); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 14 | fprintf(stderr, "BEFORE\n"); |
| 15 | pthread_t t; |
| 16 | pthread_create(&t, 0, Thread, 0); |
| 17 | X = 43; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 18 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 19 | pthread_join(t, 0); |
| 20 | fprintf(stderr, "AFTER\n"); |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | // CHECK: BEFORE |
| 25 | // CHECK: WARNING: ThreadSanitizer: data race |
| 26 | // CHECK-NOT: AFTER |
| 27 | |