Home | History | Annotate | Download | only in tsan
      1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
      2 #include "test.h"
      3 
      4 int Global;
      5 __thread int huge[1024*1024];
      6 
      7 void *Thread1(void *x) {
      8   barrier_wait(&barrier);
      9   Global++;
     10   return NULL;
     11 }
     12 
     13 void *Thread2(void *x) {
     14   pthread_mutex_t *mtx = new pthread_mutex_t;
     15   pthread_mutex_init(mtx, 0);
     16   pthread_mutex_lock(mtx);
     17   Global--;
     18   pthread_mutex_unlock(mtx);
     19   pthread_mutex_destroy(mtx);
     20   delete mtx;
     21   barrier_wait(&barrier);
     22   return NULL;
     23 }
     24 
     25 int main() {
     26   barrier_init(&barrier, 2);
     27   pthread_t t[2];
     28   pthread_create(&t[0], NULL, Thread1, NULL);
     29   pthread_create(&t[1], NULL, Thread2, NULL);
     30   pthread_join(t[0], NULL);
     31   pthread_join(t[1], NULL);
     32 }
     33 
     34 // CHECK: WARNING: ThreadSanitizer: data race
     35 // CHECK: Write of size 4 at {{.*}} by thread T1:
     36 // CHECK: Previous write of size 4 at {{.*}} by thread T2
     37 // CHECK:                                      (mutexes: write [[M1:M[0-9]+]]):
     38 // CHECK: Mutex [[M1]] is already destroyed
     39 // CHECK-NOT: Mutex {{.*}} created at
     40 
     41