Add DRD suppression patterns for races triggered by std::ostream
[valgrind.git] / helgrind / tests / tc06_two_races.c
blob4eaf9dda017464e7b604ada583422d83feb31c4b
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 /* Simple test program, has two races. A happens-before detector can only
7 ever detect one of them, though. XXX: apparently not so; Drd and H 3.4 detect both. */
9 int unprot1 = 0, unprot2 = 0, prot = 0;
10 pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER;
12 void* child_fn ( void* arg )
14 unprot1 ++;
15 pthread_mutex_lock( &mu );
16 prot ++;
17 pthread_mutex_unlock( &mu );
18 unprot2 ++;
19 return NULL;
22 int main ( void )
24 pthread_t child;
26 if (pthread_create(&child, NULL, child_fn, NULL)) {
27 perror("pthread_create");
28 exit(1);
31 unprot1 ++;
32 pthread_mutex_lock( &mu );
33 prot ++;
34 pthread_mutex_unlock( &mu );
35 unprot2 ++;
37 if (pthread_join(child, NULL)) {
38 perror("pthread join");
39 exit(1);
42 return 0;