pthread_cleanup_pop or pthread_cleanup_push Subroutine

Purpose

Activates and deactivates thread cancellation handlers.

Library

Threads Library (libpthreads.a)

Syntax

#include <pthread.h>

void pthread_cleanup_pop (execute)
int execute;

void pthread_cleanup_push (routine, arg)
void (*routine)(void *);
void *arg;

Description

The pthread_cleanup_push subroutine pushes the specified cancellation cleanup handler routine onto the calling thread's cancellation cleanup stack. The cancellation cleanup handler is popped from the cancellation cleanup stack and invoked with the argument arg when: (a) the thread exits (that is, calls pthread_exit, (b) the thread acts upon a cancellation request, or (c) the thread calls pthread_cleanup_pop with a nonzero execute argument.

The pthread_cleanup_pop subroutine removes the subroutine at the top of the calling thread's cancellation cleanup stack and optionally invokes it (if execute is nonzero).

These subroutines may be implemented as macros and will appear as statements and in pairs within the same lexical scope (that is, the pthread_cleanup_push macro may be thought to expand to a token list whose first token is '{' with pthread_cleanup_pop expanding to a token list whose last token is the corresponding '}').

The effect of calling longjmp or siglongjmp is undefined if there have been any calls to pthread_cleanup_push or pthread_cleanup_pop made without the matching call since the jump buffer was filled. The effect of calling longjmp or siglongjmp from inside a cancellation cleanup handler is also undefined unless the jump buffer was also filled in the cancellation cleanup handler.

Parameters

Item Description
execute Specifies if the popped subroutine will be executed.
routine Specifies the address of the cancellation subroutine.
arg Specifies the argument passed to the cancellation subroutine.