[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / tsan / static_init4.cc
blob85835a2520f762af12cf535f9df5bd4cccc4e75e
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>
7 struct Cache {
8 int x;
9 explicit Cache(int x)
10 : x(x) {
14 int g_other;
16 Cache *CreateCache() {
17 g_other = rand();
18 return new Cache(rand());
21 void *Thread1(void *x) {
22 static Cache *c = CreateCache();
23 if (c->x == g_other)
24 exit(1);
25 return 0;
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");
37 // CHECK-NOT: WARNING: ThreadSanitizer: data race