Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example for pthread_cleanup_{push,pop} #23

Open
vladak opened this issue Dec 13, 2018 · 0 comments
Open

add example for pthread_cleanup_{push,pop} #23

vladak opened this issue Dec 13, 2018 · 0 comments

Comments

@vladak
Copy link
Member

vladak commented Dec 13, 2018

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant