1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2#include <pthread.h> 3#include <stdlib.h> 4#include <stdio.h> 5#include <sched.h> 6 7struct Cache { 8 int x; 9 explicit Cache(int x) 10 : x(x) { 11 } 12}; 13 14int g_other; 15 16Cache *CreateCache() { 17 g_other = rand(); 18 return new Cache(rand()); 19} 20 21void *Thread1(void *x) { 22 static Cache *c = CreateCache(); 23 if (c->x == g_other) 24 exit(1); 25 return 0; 26} 27 28int main() { 29 pthread_t t[2]; 30 pthread_create(&t[0], 0, Thread1, 0); 31 pthread_create(&t[1], 0, Thread1, 0); 32 pthread_join(t[0], 0); 33 pthread_join(t[1], 0); 34 printf("PASS\n"); 35} 36 37// CHECK-NOT: WARNING: ThreadSanitizer: data race 38