benign_race.cc revision 2d1fdb26e458c4ddc04155c1d421bced3ba90cd0
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 6int Global; 7int WTFGlobal; 8 9extern "C" { 10void AnnotateBenignRaceSized(const char *f, int l, 11 void *mem, unsigned int size, const char *desc); 12void WTFAnnotateBenignRaceSized(const char *f, int l, 13 void *mem, unsigned int size, 14 const char *desc); 15} 16 17 18void *Thread(void *x) { 19 Global = 42; 20 WTFGlobal = 142; 21 return 0; 22} 23 24int 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