aboutsummaryrefslogtreecommitdiff
path: root/helgrind/tests/tc01_simple_race.c
blob: abf37b543c13d91602aa488f9a671298cce41ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

/* Simple test program, has a race.  Parent and child both modify x
   with no locking. */

int x = 0;

void* child_fn ( void* arg )
{
   /* Unprotected relative to parent */
   x++;
   return NULL;
}

int main ( void )
{
   pthread_t child;

   if (pthread_create(&child, NULL, child_fn, NULL)) {
      perror("pthread_create");
      exit(1);
   }

   /* Unprotected relative to child */
   x++;

   if (pthread_join(child, NULL)) {
      perror("pthread join");
      exit(1);
   }

   return 0;
}