2014-05-30 22:08:51 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s
|
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s
|
2013-10-16 23:35:12 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
volatile int X;
|
|
|
|
volatile int N;
|
|
|
|
void (*volatile F)();
|
|
|
|
|
|
|
|
static void foo() {
|
|
|
|
if (--N == 0)
|
|
|
|
X = 42;
|
|
|
|
else
|
|
|
|
F();
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Thread(void *p) {
|
2013-10-17 16:27:24 +08:00
|
|
|
#ifdef ORDER1
|
|
|
|
sleep(1);
|
|
|
|
#endif
|
2013-10-16 23:35:12 +08:00
|
|
|
F();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
N = 50000;
|
|
|
|
F = foo;
|
|
|
|
pthread_t t;
|
|
|
|
pthread_attr_t a;
|
|
|
|
pthread_attr_init(&a);
|
|
|
|
pthread_attr_setstacksize(&a, N * 256 + (1 << 20));
|
|
|
|
pthread_create(&t, &a, Thread, 0);
|
2013-10-17 16:27:24 +08:00
|
|
|
#ifdef ORDER2
|
2013-10-16 23:35:12 +08:00
|
|
|
sleep(1);
|
2013-10-17 16:27:24 +08:00
|
|
|
#endif
|
2013-10-16 23:35:12 +08:00
|
|
|
X = 43;
|
|
|
|
pthread_join(t, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
|
|
|
// CHECK: #100 foo
|
|
|
|
// We must output suffucuently large stack (at least 100 frames)
|
|
|
|
|