blob: abf37b543c13d91602aa488f9a671298cce41ba7 [file] [log] [blame]
sewardjb4112022007-11-09 22:49:28 +00001
2#include <pthread.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6/* Simple test program, has a race. Parent and child both modify x
7 with no locking. */
8
9int x = 0;
10
11void* child_fn ( void* arg )
12{
13 /* Unprotected relative to parent */
14 x++;
15 return NULL;
16}
17
18int main ( void )
19{
20 pthread_t child;
21
22 if (pthread_create(&child, NULL, child_fn, NULL)) {
23 perror("pthread_create");
24 exit(1);
25 }
26
27 /* Unprotected relative to child */
28 x++;
29
30 if (pthread_join(child, NULL)) {
31 perror("pthread join");
32 exit(1);
33 }
34
35 return 0;
36}