Skip to content

add example for pthread_cleanup_{push,pop} #23

Open
@vladak

Description

@vladak

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);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions