Open System Services System Calls Reference Manual (G06.25+, H06.03+)
System Functions (n - p) pthread_cleanup_push(2)
NAME
pthread_cleanup_push - (Macro) Establishes a cleanup-handler routine to be executed when the
thread terminates
LIBRARY
None. This application program interface is implemented as a macro.
SYNOPSIS
#include <spthread.h>
void pthread_cleanup_push(
void ( *routine ) ( void * ),
void *arg );
PARAMETERS
routine specifies the routine to be executed as the cleanup handler.
arg specifies an argument to be passed to the cleanup routine.
DESCRIPTION
This macro pushes the specified routine onto the calling thread’s cleanup- handler stack. The
cleanup-handler routine is popped from the stack and executed with the value specified by the
arg parameter when any of the following actions occur:
• The thread calls pthread_cleanup_pop( ) and specifies a nonzero value for the execute
parameter.
• The thread calls pthread_exit().
• The thread is canceled.
• An exception is raised and is caught when the system unwinds the calling thread’s stack
to the lexical scope of the pthread_cleanup_push() and pthread_cleanup_pop( ) pair.
This routine and pthread_cleanup_pop( ) must appear in pairs within the same lexical scope.
RELATED INFORMATION
Functions: pthread_cancel(2), pthread_cleanup_pop(2), pthread_create(2), pthread_exit(2),
pthread_testcancel(2).
STANDARDS CONFORMANCE
This macro is an extension to the XPG4 Version 2 specification. Interfaces documented on this
reference page conform to the following industry standards:
• IEEE Std 1003.1c-1995, POSIX System Application Program Interface
The use of the header file spthread.h is an HP exception to the POSIX standard.
527186-003 Hewlett-Packard Company 5−41