Home | History | Annotate | Download | only in tsan
      1 // RUN: %clangxx_tsan %s -o %t
      2 // RUN: %deflake %run %t | FileCheck %s
      3 // RUN: %deflake %run %t 1 | FileCheck %s
      4 
      5 #include <pthread.h>
      6 #include <stdio.h>
      7 #include <stdlib.h>
      8 
      9 int main(int argc, char *argv[]) {
     10   pthread_mutex_t *m = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
     11   pthread_mutex_init(m, 0);
     12   pthread_mutex_lock(m);
     13   pthread_mutex_unlock(m);
     14   pthread_mutex_destroy(m);
     15 
     16   if (argc > 1 && argv[1][0] == '1')
     17     free(m);
     18 
     19   pthread_mutex_lock(m);
     20   // CHECK: WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed)
     21   // CHECK:   #0 pthread_mutex_lock
     22   // CHECK:   #1 main {{.*}}mutex_lock_destroyed.cc:[[@LINE-3]]
     23 
     24   return 0;
     25 }
     26