Open
Description
The semantics of pthread_cleanup_push()
and pthread_cleanup_pop()
is so unusual that it warrants a demo.
Something like this could be used to demonstrate how to use cleanup function that is called no matter how the worker thread goes away:
void *
worker(void *)
{
pthread_cleanup_push(cleanup, NULL);
// ... do some work
// Make sure the cleanup is always called.
pthread_cancel(pthread_self());
pthread_testcancel();
pthread_cleanup_pop(0);
}