1#include <pthread.h> 2#include <stdlib.h> 3#include <stdio.h> 4 5struct Cache { 6 int x; 7 explicit Cache(int x) 8 : x(x) { 9 } 10}; 11 12void foo(Cache *my) { 13 static Cache *c = my ? my : new Cache(rand()); 14 if (c->x >= RAND_MAX) 15 exit(1); 16} 17 18void *Thread(void *x) { 19 foo(new Cache(rand())); 20 return 0; 21} 22 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