2 /* Check that an error is reported for various kinds of bogus
3 pthread_mutex_unlock calls. */
9 void* child_fn ( void* arg
)
11 pthread_mutex_unlock( (pthread_mutex_t
*)arg
); /* ERROR */
15 void nearly_main ( void )
18 pthread_mutex_t mx1
, mx2
;
20 /* fill bogus with values which will cause glibc's pth_mx_unlock to fail */
21 for (i
= 0; i
< 100; i
++) bogus
[i
] = 0xFFFFFFFF;
22 /* Unlocking a lock that is already unlocked */
23 pthread_mutex_init( &mx1
, NULL
);
24 pthread_mutex_lock( &mx1
);
25 pthread_mutex_unlock( &mx1
);
27 pthread_mutex_unlock( &mx1
); /* ERROR */
29 /* Unlocking a lock that is held by a different thread */
31 pthread_mutex_init( &mx2
, NULL
);
32 pthread_mutex_lock( &mx2
);
33 // start child and get it to unlock this lock
35 pthread_create( &child
, NULL
, child_fn
, (void*)&mx2
);
36 /* child runs and attempts to unlock our lock. Error
37 is reported in child_fn. */
38 pthread_join(child
, NULL
);
40 /* Unlocking a totally bogus lock. */
41 pthread_mutex_unlock( (pthread_mutex_t
*) &bogus
[50] ); /* ERROR */
43 /* Now we get a freeing-locked-lock error, since the stack
44 frame is removed whilst mx2 is still locked. */
49 nearly_main(); fprintf(stderr
, "---------------------\n" );