Home | History | Annotate | Download | only in tsan
      1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
      2 #include <pthread.h>
      3 #include <stdio.h>
      4 #include <unistd.h>
      5 
      6 int Global;
      7 int WTFGlobal;
      8 
      9 extern "C" {
     10 void AnnotateBenignRaceSized(const char *f, int l,
     11                              void *mem, unsigned int size, const char *desc);
     12 void WTFAnnotateBenignRaceSized(const char *f, int l,
     13                                 void *mem, unsigned int size,
     14                                 const char *desc);
     15 }
     16 
     17 
     18 void *Thread(void *x) {
     19   Global = 42;
     20   WTFGlobal = 142;
     21   return 0;
     22 }
     23 
     24 int main() {
     25   AnnotateBenignRaceSized(__FILE__, __LINE__,
     26                           &Global, sizeof(Global), "Race on Global");
     27   WTFAnnotateBenignRaceSized(__FILE__, __LINE__,
     28                              &WTFGlobal, sizeof(WTFGlobal),
     29                              "Race on WTFGlobal");
     30   pthread_t t;
     31   pthread_create(&t, 0, Thread, 0);
     32   sleep(1);
     33   Global = 43;
     34   WTFGlobal = 143;
     35   pthread_join(t, 0);
     36   printf("OK\n");
     37 }
     38 
     39 // CHECK-NOT: WARNING: ThreadSanitizer: data race
     40