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 {
AA7 A() {
8 sem_init(&sem_, 0, 0);
9 }
FA10 virtual void F() {
11 }
DoneA12 void Done() {
13 sem_post(&sem_);
14 }
~AA15 virtual ~A() {
16 }
17 sem_t sem_;
18 };
19
20 struct B : A {
FB21 virtual void F() {
22 }
~BB23 virtual ~B() {
24 sem_wait(&sem_);
25 sem_destroy(&sem_);
26 }
27 };
28
29 static A *obj = new B;
30
Thread1(void * x)31 void *Thread1(void *x) {
32 obj->F();
33 obj->Done();
34 return NULL;
35 }
36
Thread2(void * x)37 void *Thread2(void *x) {
38 delete obj;
39 return NULL;
40 }
41
main()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");
49 }
50 // CHECK: PASS
51 // CHECK-NOT: WARNING: ThreadSanitizer: data race
52