[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / vptr_harmful_race.cc
blob0105c4cedd998f9f47a46f078a424d2b8c8b9218
1 // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <semaphore.h>
4 #include <stdio.h>
5 #include <unistd.h>
7 struct A {
8 A() {
9 sem_init(&sem_, 0, 0);
11 virtual void F() {
13 void Done() {
14 sem_post(&sem_);
16 virtual ~A() {
17 sem_wait(&sem_);
18 sem_destroy(&sem_);
20 sem_t sem_;
23 struct B : A {
24 virtual void F() {
26 virtual ~B() { }
29 static A *obj = new B;
31 void *Thread1(void *x) {
32 obj->F();
33 obj->Done();
34 return NULL;
37 void *Thread2(void *x) {
38 sleep(1);
39 delete obj;
40 return NULL;
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);
51 // CHECK: WARNING: ThreadSanitizer: data race on vptr