2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / tsan / vptr_benign_race.C
blob283684bcfa9c8108618a706d359cdceb73ccc730
1 #include <pthread.h>
2 #include <semaphore.h>
3 #include <stdio.h>
5 struct A {
6   A() {
7     sem_init(&sem_, 0, 0);
8   }
9   virtual void F() {
10   }
11   void Done() {
12     sem_post(&sem_);
13   }
14   virtual ~A() {
15   }
16   sem_t sem_;
19 struct B : A {
20   virtual void F() {
21   }
22   virtual ~B() {
23     sem_wait(&sem_);
24     sem_destroy(&sem_);
25   }
28 static A *obj = new B;
30 void *Thread1(void *x) {
31   obj->F();
32   obj->Done();
33   return NULL;
36 void *Thread2(void *x) {
37   delete obj;
38   return NULL;
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   fprintf(stderr, "PASS\n");
49 /* { dg-output "PASS.*" } */