Home | History | Annotate | Download | only in tsan
      1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
      2 #include <pthread.h>
      3 #include <stdio.h>
      4 #include <stddef.h>
      5 #include <unistd.h>
      6 
      7 int GlobalData[10];
      8 
      9 void *Thread(void *a) {
     10   sleep(1);
     11   GlobalData[2] = 42;
     12   return 0;
     13 }
     14 
     15 int main() {
     16   fprintf(stderr, "addr=%p\n", GlobalData);
     17   pthread_t t;
     18   pthread_create(&t, 0, Thread, 0);
     19   GlobalData[2] = 43;
     20   pthread_join(t, 0);
     21 }
     22 
     23 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
     24 // CHECK: WARNING: ThreadSanitizer: data race
     25 // CHECK: Location is global 'GlobalData' of size 40 at [[ADDR]] ({{.*}}+0x{{[0-9,a-f]+}})
     26 
     27