Greg Fitzgerald | b8aae54 | 2014-04-30 21:34:17 +0000 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
Dmitry Vyukov | 3ab6b23 | 2015-01-21 13:50:02 +0000 | [diff] [blame] | 2 | #include "test.h" |
Dmitry Vyukov | fd5ebcd | 2012-12-06 12:16:15 +0000 | [diff] [blame] | 3 | |
| 4 | int Global; |
| 5 | |
| 6 | extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l); |
| 7 | extern "C" void AnnotateIgnoreWritesEnd(const char *f, int l); |
| 8 | extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l); |
| 9 | extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l); |
| 10 | |
| 11 | void *Thread(void *x) { |
| 12 | AnnotateIgnoreWritesBegin(__FILE__, __LINE__); |
| 13 | AnnotateIgnoreReadsBegin(__FILE__, __LINE__); |
| 14 | Global = 42; |
| 15 | AnnotateIgnoreReadsEnd(__FILE__, __LINE__); |
| 16 | AnnotateIgnoreWritesEnd(__FILE__, __LINE__); |
Dmitry Vyukov | 3ab6b23 | 2015-01-21 13:50:02 +0000 | [diff] [blame] | 17 | barrier_wait(&barrier); |
Dmitry Vyukov | fd5ebcd | 2012-12-06 12:16:15 +0000 | [diff] [blame] | 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | int main() { |
Dmitry Vyukov | 3ab6b23 | 2015-01-21 13:50:02 +0000 | [diff] [blame] | 22 | barrier_init(&barrier, 2); |
Dmitry Vyukov | fd5ebcd | 2012-12-06 12:16:15 +0000 | [diff] [blame] | 23 | pthread_t t; |
| 24 | pthread_create(&t, 0, Thread, 0); |
Dmitry Vyukov | 3ab6b23 | 2015-01-21 13:50:02 +0000 | [diff] [blame] | 25 | barrier_wait(&barrier); |
Dmitry Vyukov | fd5ebcd | 2012-12-06 12:16:15 +0000 | [diff] [blame] | 26 | Global = 43; |
| 27 | pthread_join(t, 0); |
Renato Golin | 1f42286 | 2016-04-15 12:34:00 +0000 | [diff] [blame] | 28 | fprintf(stderr, "OK\n"); |
Dmitry Vyukov | fd5ebcd | 2012-12-06 12:16:15 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Dmitry Vyukov | e3e0557 | 2012-12-06 15:42:54 +0000 | [diff] [blame] | 31 | // CHECK-NOT: WARNING: ThreadSanitizer: data race |