• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 struct Cache {
8   int x;
CacheCache9   explicit Cache(int x)
10     : x(x) {
11   }
12 };
13 
14 int g_other;
15 
CreateCache()16 Cache *CreateCache() {
17   g_other = rand();
18   return new Cache(rand());
19 }
20 
Thread1(void * x)21 void *Thread1(void *x) {
22   static Cache *c = CreateCache();
23   if (c->x == g_other)
24     exit(1);
25   return 0;
26 }
27 
main()28 int 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