2014-05-30 22:08:51 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2012-09-01 01:27:49 +08:00
|
|
|
|
|
|
|
int X = 0;
|
|
|
|
|
2012-09-24 21:35:46 +08:00
|
|
|
void MySleep() {
|
2015-01-21 21:50:02 +08:00
|
|
|
sleep(1); // the sleep that must appear in the report
|
2012-09-24 21:35:46 +08:00
|
|
|
}
|
|
|
|
|
2012-09-01 01:27:49 +08:00
|
|
|
void *Thread(void *p) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-09-24 21:35:46 +08:00
|
|
|
MySleep(); // Assume the main thread has done the write.
|
2012-09-01 01:27:49 +08:00
|
|
|
X = 42;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2012-09-01 01:27:49 +08:00
|
|
|
pthread_t t;
|
|
|
|
pthread_create(&t, 0, Thread, 0);
|
|
|
|
X = 43;
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2012-09-01 01:27:49 +08:00
|
|
|
pthread_join(t, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
|
|
|
// ...
|
|
|
|
// CHECK: As if synchronized via sleep:
|
2012-12-07 17:24:57 +08:00
|
|
|
// CHECK-NEXT: #0 sleep
|
2012-09-01 01:27:49 +08:00
|
|
|
// CHECK-NEXT: #1 MySleep
|
2012-09-24 21:35:46 +08:00
|
|
|
// CHECK-NEXT: #2 Thread
|