pthread_cleanup_push Subroutine Purpose Pushes a routine onto the calling thread's cleanup stack. Library Threads Library (libpthreads.a) Syntax #include void pthread_cleanup_push (routine, arg) void (*routine) (void *); void *arg; Description The pthread_cleanup_push subroutine pushes the routine routine onto the calling thread's cleanup stack. The cleanup stack is an ordinary LIFO routines stack, used for performing all necessary cleanups at thread termination. The stacked cleanup routines are executed when the thread terminates or when it is canceled. When the entire process is terminated, due to a signal or to a call to either the exec, exit, or fork subroutines, the cleanup routines are not called. The cleanup routines are called with the arg parameter as the single parameter. It is a void pointer; it can reference any kind of data. It is not recommended to cast this pointer into a scalar data type (int for example), because the casts may not be portable. For each call to the pthread_cleanup_push subroutine, there should be a call to the pthread_cleanup_pop subroutine in the same function and in the same block of statement. Otherwise, the compiler may fail compiling the program, or the program would have an unpredictable behaviour when porting to other systems. The reason is that, on non-AIX systems, the pthread_cleanup_push subroutine may be implemented as a macro opening a block of statements. Note: The pthread.h header file must be the first included file of each source file using the threads library. Parameters routine Points to the cleanup routine. arg Points to the single argument to be passed to the cleanup routine. Implementation Specifics This subroutine is part of the Base Operating System (BOS) Runtime. Related Information The pthread_cleanup_pop subroutine, pthread_exit subroutine. Terminating Threads. Threads Library Quick Reference.