blob: e410006ddc72658d8ce08c40657abe2c3dbc7df6 [file] [log] [blame]
Greg Fitzgeraldb8aae542014-04-30 21:34:17 +00001// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
Dmitry Vyukov3ab6b232015-01-21 13:50:02 +00002#include "test.h"
Dmitry Vyukovfd5ebcd2012-12-06 12:16:15 +00003
4int Global;
5
6extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
7extern "C" void AnnotateIgnoreWritesEnd(const char *f, int l);
8extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
9extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l);
10
11void *Thread(void *x) {
12 AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
13 AnnotateIgnoreReadsBegin(__FILE__, __LINE__);
14 Global = 42;
15 AnnotateIgnoreReadsEnd(__FILE__, __LINE__);
16 AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
Dmitry Vyukov3ab6b232015-01-21 13:50:02 +000017 barrier_wait(&barrier);
Dmitry Vyukovfd5ebcd2012-12-06 12:16:15 +000018 return 0;
19}
20
21int main() {
Dmitry Vyukov3ab6b232015-01-21 13:50:02 +000022 barrier_init(&barrier, 2);
Dmitry Vyukovfd5ebcd2012-12-06 12:16:15 +000023 pthread_t t;
24 pthread_create(&t, 0, Thread, 0);
Dmitry Vyukov3ab6b232015-01-21 13:50:02 +000025 barrier_wait(&barrier);
Dmitry Vyukovfd5ebcd2012-12-06 12:16:15 +000026 Global = 43;
27 pthread_join(t, 0);
Renato Golin1f422862016-04-15 12:34:00 +000028 fprintf(stderr, "OK\n");
Dmitry Vyukovfd5ebcd2012-12-06 12:16:15 +000029}
30
Dmitry Vyukove3e05572012-12-06 15:42:54 +000031// CHECK-NOT: WARNING: ThreadSanitizer: data race