[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / cond_race.cc
blob08d6901e6f0ef372a1dce4415ef3c5127a0e9615
1 // RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
2 // CHECK-NOT: unlock of unlocked mutex
3 // CHECK: ThreadSanitizer: data race
4 // CHECK: pthread_cond_signal
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <pthread.h>
9 #include <unistd.h>
11 struct Ctx {
12 pthread_mutex_t m;
13 pthread_cond_t c;
14 bool done;
17 void *thr(void *p) {
18 Ctx *c = (Ctx*)p;
19 pthread_mutex_lock(&c->m);
20 c->done = true;
21 pthread_mutex_unlock(&c->m);
22 pthread_cond_signal(&c->c);
23 return 0;
26 int main() {
27 Ctx *c = new Ctx();
28 pthread_mutex_init(&c->m, 0);
29 pthread_cond_init(&c->c, 0);
30 pthread_t th;
31 pthread_create(&th, 0, thr, c);
32 pthread_mutex_lock(&c->m);
33 while (!c->done)
34 pthread_cond_wait(&c->c, &c->m);
35 pthread_mutex_unlock(&c->m);
36 // w/o this sleep, it can be reported as use-after-free
37 sleep(1);
38 delete c;
39 pthread_join(th, 0);