Add DRD suppression patterns for races triggered by std::ostream
[valgrind.git] / helgrind / tests / tc05_simple_race.c
blob0d20a51b6d02941d44ef86edc1ec40aa9ef7bb18
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 /* Simple test program, has a race. Parent and child both modify y
7 with no locking. This is the program shown in Fig 2 of the
8 original Eraser paper by Savage et al. */
10 int y = 0, v = 0;
11 pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER;
13 void* child_fn ( void* arg )
15 /* "Thread 2" in the paper */
16 pthread_mutex_lock( &mu );
17 v = v + 1;
18 pthread_mutex_unlock( &mu );
19 y = y + 1;
20 return NULL;
23 int main ( void )
25 const struct timespec delay = { 0, 100 * 1000 * 1000 };
26 pthread_t child;
27 if (pthread_create(&child, NULL, child_fn, NULL)) {
28 perror("pthread_create");
29 exit(1);
31 nanosleep(&delay, 0);
32 /* "Thread 1" in the paper */
33 y = y + 1;
34 pthread_mutex_lock( &mu );
35 v = v + 1;
36 pthread_mutex_unlock( &mu );
38 if (pthread_join(child, NULL)) {
39 perror("pthread join");
40 exit(1);
43 return 0;