2 /* Check that an error is reported for various kinds of bogus
3 pthread_mutex_unlock calls. */
10 void* child_fn ( void* arg
)
12 pthread_mutex_unlock( (pthread_mutex_t
*)arg
); /* ERROR */
16 void nearly_main ( void )
19 pthread_mutex_t mx1
, mx2
;
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 */
46 /* Now we get a freeing-locked-lock error, since the stack
47 frame is removed whilst mx2 is still locked. */
52 nearly_main(); fprintf(stderr
, "---------------------\n" );