blob: 4b050c9fa69bbe1767e3c9009ca2dd6a99f65155 [file] [log] [blame]
Kostya Serebryanyff15ef02012-05-10 14:18:22 +00001#include <pthread.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include <sched.h>
5
6struct Cache {
7 int x;
8 Cache(int x)
9 : x(x) {
10 }
11};
12
13void *AsyncInit(void *p) {
14 return new Cache((int)(long)p);
15}
16
17Cache *CreateCache() {
18 pthread_t t;
19 pthread_create(&t, 0, AsyncInit, (void*)rand());
20 void *res;
21 pthread_join(t, &res);
22 return (Cache*)res;
23}
24
25void *Thread1(void *x) {
26 static Cache *c = CreateCache();
27 if (c->x >= RAND_MAX)
28 exit(1);
29 return 0;
30}
31
32int main() {
33 pthread_t t[2];
34 pthread_create(&t[0], 0, Thread1, 0);
35 pthread_create(&t[1], 0, Thread1, 0);
36 pthread_join(t[0], 0);
37 pthread_join(t[1], 0);
38}
39
40// CHECK-NOT: WARNING: ThreadSanitizer: data race