VMS Help  —  POSIX Threads, PTHREAD routines, pthread_cleanup_push
    (Macro) Establishes a cleanup handler routine to be executed when
    the thread exits or is canceled.

1  –  C Binding

    #include <phtread.h>

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

2  –  Arguments

 routine

    Routine executed as the cleanup handler.

 arg

    Argument passed to the cleanup handler routine.

3  –  Description

    This routine pushes the specified routine onto the calling
    thread's cleanup handler stack. The cleanup handler routine is
    popped from the stack and called with the arg argument when any
    of the following actions occur:

    o  The thread calls pthread_cleanup_pop() and specifies a nonzero
       value for the execute argument.

    o  The thread calls pthread_exit().

    o  The thread is canceled.

    o  An exception is raised and is caught when the Threads Library
       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() are implemented as macros
    and must appear as statements and in pairs within the same
    lexical scope. You can think of the pthread_cleanup_push() macro
    as expanding to a string whose first character is a left brace
    ({) and pthread_cleanup_pop() as expanding to a string containing
    the corresponding right brace (}). This routine and pthread_
    cleanup_pop() are implemented as exceptions, and may not work
    in a C++ environment. (See <REFERENCE>(exceptions_chap) for more
    information.)

4  –  Return Values

    None

5  –  Associated Routines

       pthread_cancel()
       pthread_cleanup_pop()
       pthread_create()
       pthread_exit()
       pthread_testcancel()
Close Help