tsan: add flag to control symbolizer flush frequency
[blocksruntime.git] / lib / tsan / lit_tests / vptr_harmful_race.cc
blobf51ba7ee57f0b4ebf603a2f21447dcff7ee87b11
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>
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() {
16 sem_wait(&sem_);
17 sem_destroy(&sem_);
19 sem_t sem_;
22 struct B : A {
23 virtual void F() {
25 virtual ~B() { }
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);
49 // CHECK: WARNING: ThreadSanitizer: data race