Home | History | Annotate | Download | only in tsan
      1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
      2 // CHECK-NOT: WARNING
      3 // CHECK: OK
      4 
      5 #include <stdio.h>
      6 #include <stdlib.h>
      7 #include <pthread.h>
      8 #include <unistd.h>
      9 
     10 pthread_mutex_t m;
     11 pthread_cond_t c;
     12 int x;
     13 
     14 void *thr1(void *p) {
     15   pthread_mutex_lock(&m);
     16   pthread_cleanup_push((void(*)(void *arg))pthread_mutex_unlock, &m);
     17   while (x == 0)
     18     pthread_cond_wait(&c, &m);
     19   pthread_cleanup_pop(1);
     20   return 0;
     21 }
     22 
     23 int main() {
     24   pthread_t th;
     25 
     26   pthread_mutex_init(&m, 0);
     27   pthread_cond_init(&c, 0);
     28 
     29   pthread_create(&th, 0, thr1, 0);
     30   sleep(1);  // let it block on cond var
     31   pthread_cancel(th);
     32 
     33   pthread_join(th, 0);
     34   pthread_mutex_lock(&m);
     35   pthread_mutex_unlock(&m);
     36   fprintf(stderr, "OK\n");
     37 }
     38