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