2014-05-01 05:34:17 +08:00
|
|
|
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2013-04-02 19:21:53 +08:00
|
|
|
|
|
|
|
int Global;
|
|
|
|
int WTFGlobal;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
void AnnotateBenignRaceSized(const char *f, int l,
|
|
|
|
void *mem, unsigned int size, const char *desc);
|
|
|
|
void WTFAnnotateBenignRaceSized(const char *f, int l,
|
|
|
|
void *mem, unsigned int size,
|
|
|
|
const char *desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *Thread(void *x) {
|
|
|
|
Global = 42;
|
|
|
|
WTFGlobal = 142;
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-04-02 19:21:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2013-04-02 19:21:53 +08:00
|
|
|
AnnotateBenignRaceSized(__FILE__, __LINE__,
|
|
|
|
&Global, sizeof(Global), "Race on Global");
|
|
|
|
WTFAnnotateBenignRaceSized(__FILE__, __LINE__,
|
|
|
|
&WTFGlobal, sizeof(WTFGlobal),
|
|
|
|
"Race on WTFGlobal");
|
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, 0, Thread, 0);
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-04-02 19:21:53 +08:00
|
|
|
Global = 43;
|
|
|
|
WTFGlobal = 143;
|
|
|
|
pthread_join(t, 0);
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "OK\n");
|
2013-04-02 19:21:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-NOT: WARNING: ThreadSanitizer: data race
|