Home | History | Annotate | Download | only in tsan
      1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
      2 // Race between an aligned access and an unaligned access, which
      3 // touches the same memory region.
      4 // This is a real race which is not detected by tsan.
      5 // https://code.google.com/p/thread-sanitizer/issues/detail?id=17
      6 #include <pthread.h>
      7 #include <stdio.h>
      8 #include <stdint.h>
      9 
     10 uint64_t Global[2];
     11 
     12 void *Thread1(void *x) {
     13   Global[1]++;
     14   return NULL;
     15 }
     16 
     17 void *Thread2(void *x) {
     18   char *p1 = reinterpret_cast<char *>(&Global[0]);
     19   uint64_t *p4 = reinterpret_cast<uint64_t *>(p1 + 1);
     20   (*p4)++;
     21   return NULL;
     22 }
     23 
     24 int main() {
     25   pthread_t t[2];
     26   pthread_create(&t[0], NULL, Thread1, NULL);
     27   pthread_create(&t[1], NULL, Thread2, NULL);
     28   pthread_join(t[0], NULL);
     29   pthread_join(t[1], NULL);
     30   printf("Pass\n");
     31   // CHECK-NOT: ThreadSanitizer: data race
     32   // CHECK: Pass
     33   return 0;
     34 }
     35