4.9.   153

        -
       ,  
   .

4.9.1.2.   

, ""  ,   ,  -
    . ,   ,
     ,    -
  .  Pthread   
  "    ".    
 -  (cleanup stack),  
   ( ),     
 .          ,
  pthread_cleanup_push ().



#include <pthread.h>

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

void pthread_cleanup_pop(int execute);

 routine     ,   
 .  arg  ,  
routine-,        
pthread_exit (),   ""      -
   pthread_cleanup_pop ()    
execute. ,   routine,    .

 pthread_cleanup_pop()   routine-  -
     .  execute 
  1  0.     1,   routine-
,        .    -
  ,     pthread_cleanup_pop ().
   execute  0,     
   routine-.

   ,       
(push)      (pop)      
  . ,   funcA ()  -
 cleanup-      :

void *?uncA(void *X)
{

int *Tid;

Tid = new int;

//   .

// . . .

pthread_cleanup_push(cleanup_?uncA,Tid) ;

//   .

//. . .

pthread_cleanup_pop(0);