1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 #include <pthread.h> 3 #include <semaphore.h> 4 #include <stdio.h> 5 #include <unistd.h> 6 7 struct A { 8 A() { 9 sem_init(&sem_, 0, 0); 10 } 11 virtual void F() { 12 } 13 void Done() { 14 sem_post(&sem_); 15 } 16 virtual ~A() { 17 sem_wait(&sem_); 18 sem_destroy(&sem_); 19 } 20 sem_t sem_; 21 }; 22 23 struct B : A { 24 virtual void F() { 25 } 26 virtual ~B() { } 27 }; 28 29 static A *obj = new B; 30 31 void *Thread1(void *x) { 32 sleep(1); 33 obj->F(); 34 obj->Done(); 35 return NULL; 36 } 37 38 void *Thread2(void *x) { 39 delete obj; 40 return NULL; 41 } 42 43 int main() { 44 pthread_t t[2]; 45 pthread_create(&t[0], NULL, Thread1, NULL); 46 pthread_create(&t[1], NULL, Thread2, NULL); 47 pthread_join(t[0], NULL); 48 pthread_join(t[1], NULL); 49 } 50 51 // CHECK: WARNING: ThreadSanitizer: data race on vptr 52