jsgf | 12475f6 | 2003-10-16 06:09:41 +0000 | [diff] [blame] | 1 | /* A simple race */ |
2 | |||||
3 | #include <pthread.h> | ||||
4 | #include <unistd.h> | ||||
5 | |||||
6 | static int shared; | ||||
7 | |||||
8 | static void *th(void *v) | ||||
9 | { | ||||
10 | shared++; | ||||
11 | |||||
12 | return 0; | ||||
13 | } | ||||
14 | |||||
15 | int main() | ||||
16 | { | ||||
17 | pthread_t a, b; | ||||
18 | |||||
19 | pthread_create(&a, NULL, th, NULL); | ||||
20 | sleep(1); /* force ordering */ | ||||
21 | pthread_create(&b, NULL, th, NULL); | ||||
22 | |||||
23 | pthread_join(a, NULL); | ||||
24 | pthread_join(b, NULL); | ||||
25 | |||||
26 | return 0; | ||||
27 | } |