2015-11-20 01:28:46 +08:00
|
|
|
// RUN: %clang_tsan -O1 %s -o %t && %env_tsan_opts=halt_on_error=1 %deflake %run %t | FileCheck %s
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2013-08-13 23:33:00 +08:00
|
|
|
|
|
|
|
int X;
|
|
|
|
|
|
|
|
void *Thread(void *x) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-08-13 23:33:00 +08:00
|
|
|
X = 42;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2013-08-13 23:33:00 +08:00
|
|
|
fprintf(stderr, "BEFORE\n");
|
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, 0, Thread, 0);
|
|
|
|
X = 43;
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-08-13 23:33:00 +08:00
|
|
|
pthread_join(t, 0);
|
|
|
|
fprintf(stderr, "AFTER\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: BEFORE
|
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
|
|
|
// CHECK-NOT: AFTER
|
|
|
|
|