1 #include <pthread.h> 2 #include <stdlib.h> 3 #include <stdio.h> 4 5 struct Cache { 6 int x; CacheCache7 explicit Cache(int x) 8 : x(x) { 9 } 10 }; 11 foo(Cache * my)12void foo(Cache *my) { 13 static Cache *c = my ? my : new Cache(rand()); 14 if (c->x >= RAND_MAX) 15 exit(1); 16 } 17 Thread(void * x)18void *Thread(void *x) { 19 foo(new Cache(rand())); 20 return 0; 21 } 22 main()23int main() { 24 pthread_t t[2]; 25 pthread_create(&t[0], 0, Thread, 0); 26 pthread_create(&t[1], 0, Thread, 0); 27 pthread_join(t[0], 0); 28 pthread_join(t[1], 0); 29 } 30 31 // CHECK-NOT: WARNING: ThreadSanitizer: data race 32