[ASan] Add references to the issue tracker about malloc/free/new/delete mismatch...
[blocksruntime.git] / test / tsan / cond.c
blob05ea672c6c1c6deadd3b47ce3646627c09ac225d
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // CHECK-NOT: WARNING: ThreadSanitizer: data race
3 // CHECK-NOT: ThreadSanitizer WARNING: double lock
4 // CHECK-NOT: ThreadSanitizer WARNING: mutex unlock by another thread
5 // CHECK: OK
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <pthread.h>
11 pthread_mutex_t m;
12 pthread_cond_t c;
13 int x;
15 void *thr1(void *p) {
16 int i;
18 for (i = 0; i < 10; i += 2) {
19 pthread_mutex_lock(&m);
20 while (x != i)
21 pthread_cond_wait(&c, &m);
22 x = i + 1;
23 pthread_cond_signal(&c);
24 pthread_mutex_unlock(&m);
26 return 0;
29 void *thr2(void *p) {
30 int i;
32 for (i = 1; i < 10; i += 2) {
33 pthread_mutex_lock(&m);
34 while (x != i)
35 pthread_cond_wait(&c, &m);
36 x = i + 1;
37 pthread_mutex_unlock(&m);
38 pthread_cond_broadcast(&c);
40 return 0;
43 int main() {
44 pthread_t th1, th2;
46 pthread_mutex_init(&m, 0);
47 pthread_cond_init(&c, 0);
48 pthread_create(&th1, 0, thr1, 0);
49 pthread_create(&th2, 0, thr2, 0);
50 pthread_join(th1, 0);
51 pthread_join(th2, 0);
52 fprintf(stderr, "OK\n");