Add DRD suppression patterns for races triggered by std::ostream
[valgrind.git] / helgrind / tests / tc04_free_lock.c
blobc1ffa254a63a1a240d89ae2bffa9f690fa55a58c
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <assert.h>
7 /* Delete memory that has a held lock and see what happens. */
9 typedef struct { int stuff[2000];
10 pthread_mutex_t lock; int morestuff[2000]; } XX;
12 void bar ( void );
13 void foo ( void );
15 int main ( void )
17 XX* xx = malloc(sizeof(XX));
18 assert(xx);
20 pthread_mutex_init( &xx->lock, NULL );
22 pthread_mutex_lock( &xx->lock );
24 free(xx);
26 bar();
27 foo();
28 bar();
30 return 0;
33 /* Try the same, on the stack */
34 void bar ( void )
36 pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
37 // pthread_mutex_init( &mx, NULL );
38 pthread_mutex_lock( &mx );
39 /* now just abandon mx */
42 /* and again ... */
43 void foo ( void )
45 pthread_mutex_t mx;
46 pthread_mutex_init( &mx, NULL );
47 pthread_mutex_lock( &mx );
48 /* now just abandon mx */