[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / static_init5.cc
blob1d0ed6d54ca25f9288ff7b3a5bc61877e1ca9aa4
1 // RUN: %clangxx_tsan -O1 %s -o %t && %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 void *AsyncInit(void *p) {
15 return new Cache((int)(long)p);
18 Cache *CreateCache() {
19 pthread_t t;
20 pthread_create(&t, 0, AsyncInit, (void*)(long)rand());
21 void *res;
22 pthread_join(t, &res);
23 return (Cache*)res;
26 void *Thread1(void *x) {
27 static Cache *c = CreateCache();
28 if (c->x >= RAND_MAX)
29 exit(1);
30 return 0;
33 int main() {
34 pthread_t t[2];
35 pthread_create(&t[0], 0, Thread1, 0);
36 pthread_create(&t[1], 0, Thread1, 0);
37 pthread_join(t[0], 0);
38 pthread_join(t[1], 0);
39 printf("PASS\n");
42 // CHECK-NOT: WARNING: ThreadSanitizer: data race