[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / tsan / vptr_benign_race.cc
blob92a2b326e717c1f313da04c3a07de22709eda90c
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <semaphore.h>
4 #include <stdio.h>
6 struct A {
7 A() {
8 sem_init(&sem_, 0, 0);
10 virtual void F() {
12 void Done() {
13 sem_post(&sem_);
15 virtual ~A() {
17 sem_t sem_;
20 struct B : A {
21 virtual void F() {
23 virtual ~B() {
24 sem_wait(&sem_);
25 sem_destroy(&sem_);
29 static A *obj = new B;
31 void *Thread1(void *x) {
32 obj->F();
33 obj->Done();
34 return NULL;
37 void *Thread2(void *x) {
38 delete obj;
39 return NULL;
42 int main() {
43 pthread_t t[2];
44 pthread_create(&t[0], NULL, Thread1, NULL);
45 pthread_create(&t[1], NULL, Thread2, NULL);
46 pthread_join(t[0], NULL);
47 pthread_join(t[1], NULL);
48 fprintf(stderr, "PASS\n");
50 // CHECK: PASS
51 // CHECK-NOT: WARNING: ThreadSanitizer: data race