Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
2.  Basic Threads Programming The Threads Library Create a Cancellation Point pthread_testcancel(3THR)  Previous   Contents   Next 
   
 

Push a Handler Onto the Stack

Use cleanup handlers to restore conditions to a state consistent with that at the point of origin, such as cleaning up allocated resources and restoring invariants. Use the pthread_cleanup_push(3THR) and pthread_cleanup_pop(3THR) functions to manage the handlers.

Cleanup handlers are pushed and popped in the same lexical scope of a program. They should always match; otherwise compiler errors will be generated.

pthread_cleanup_push(3THR)

Use pthread_cleanup_push(3THR) to push a cleanup handler onto a cleanup stack (LIFO).

Prototype:

void pthread_cleanup_push(void(*routine)(void *), void *args);
#include <pthread.h>

/* push the handler "routine" on cleanup stack */
pthread_cleanup_push (routine, arg); 

Pull a Handler Off the Stack

pthread_cleanup_pop(3THR)

Use pthread_cleanup_pop(3THR) to pull the cleanup handler off the cleanup stack.

A nonzero argument in the pop function removes the handler from the stack and executes it. An argument of zero pops the handler without executing it.

pthread_cleanup_pop() is effectively called with a nonzero argument if a thread either explicitly or implicitly calls pthread_exit(3THR) or if the thread accepts a cancel request.

Prototype:
void pthread_cleanup_pop(int execute);
#include <pthread.h>

/* pop the "func" out of cleanup stack and execute "func" */
pthread_cleanup_pop (1);

/* pop the "func" and DONT execute "func" */
pthread_cleanup_pop (0); 

There are no return values.

 
 
 
  Previous   Contents   Next