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 <stddef.h>
      4 #include <stdio.h>
      5 #include <string.h>
      6 #include <unistd.h>
      7 
      8 int y[4], z[4];
      9 
     10 void *MemMoveThread(void *a) {
     11   memmove((int*)a, z, 16);
     12   return NULL;
     13 }
     14 
     15 void *MemSetThread(void *a) {
     16   sleep(1);
     17   memset((int*)a, 0, 16);
     18   return NULL;
     19 }
     20 
     21 int main() {
     22   pthread_t t[2];
     23   // Race on y between memmove and memset
     24   pthread_create(&t[0], NULL, MemMoveThread, y);
     25   pthread_create(&t[1], NULL, MemSetThread, y);
     26   pthread_join(t[0], NULL);
     27   pthread_join(t[1], NULL);
     28 
     29   printf("PASS\n");
     30   return 0;
     31 }
     32 
     33 // CHECK: WARNING: ThreadSanitizer: data race
     34 // CHECK:   #0 memset
     35 // CHECK:   #1 MemSetThread
     36 // CHECK:  Previous write
     37 // CHECK:   #0 memmove
     38 // CHECK:   #1 MemMoveThread
     39