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 char s[] = "abracadabra";
      5 
      6 void *Thread0(void *p) {
      7   puts(s);
      8   barrier_wait(&barrier);
      9   return 0;
     10 }
     11 
     12 void *Thread1(void *p) {
     13   barrier_wait(&barrier);
     14   s[3] = 'z';
     15   return 0;
     16 }
     17 
     18 int main() {
     19   barrier_init(&barrier, 2);
     20   pthread_t th[2];
     21   pthread_create(&th[0], 0, Thread0, 0);
     22   pthread_create(&th[1], 0, Thread1, 0);
     23   pthread_join(th[0], 0);
     24   pthread_join(th[1], 0);
     25   fprintf(stderr, "DONE");
     26 }
     27 
     28 // CHECK: WARNING: ThreadSanitizer: data race
     29 // CHECK: DONE
     30 
     31