Add 469782 to NEWS
[valgrind.git] / helgrind / tests / tc09_bad_unlock.c
blob9e4a8801d77a7a79d53f56ac00ae4a6fcda000cd
2 /* Check that an error is reported for various kinds of bogus
3 pthread_mutex_unlock calls. */
5 #include <pthread.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "config.h"
10 void* child_fn ( void* arg )
12 pthread_mutex_unlock( (pthread_mutex_t*)arg ); /* ERROR */
13 return NULL;
16 void nearly_main ( void )
18 pthread_t child;
19 pthread_mutex_t mx1, mx2;
20 int bogus[100], i;
21 /* fill bogus with values which will cause glibc's pth_mx_unlock to fail */
22 for (i = 0; i < 100; i++) bogus[i] = 0xFFFFFFFF;
23 /* Unlocking a lock that is already unlocked */
24 pthread_mutex_init( &mx1, NULL );
25 pthread_mutex_lock( &mx1 );
26 pthread_mutex_unlock( &mx1 );
28 pthread_mutex_unlock( &mx1 ); /* ERROR */
30 /* Unlocking a lock that is held by a different thread */
32 pthread_mutex_init( &mx2, NULL );
33 pthread_mutex_lock( &mx2 );
34 // start child and get it to unlock this lock
36 pthread_create( &child, NULL, child_fn, (void*)&mx2 );
37 /* child runs and attempts to unlock our lock. Error
38 is reported in child_fn. */
39 pthread_join(child, NULL );
41 #if !defined(VGO_freebsd)
42 /* Unlocking a totally bogus lock. */
43 pthread_mutex_unlock( (pthread_mutex_t*) &bogus[50] ); /* ERROR */
44 #endif
46 /* Now we get a freeing-locked-lock error, since the stack
47 frame is removed whilst mx2 is still locked. */
50 int main ( void )
52 nearly_main(); fprintf(stderr, "---------------------\n" );
53 nearly_main();
54 return 0;