#include <pthread.h>
void pthread_cleanup_push_defer_np(typeof(void (void *)) *routine,
void *arg);
void pthread_cleanup_pop_restore_np(int execute);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
pthread_cleanup_push_defer_np(), pthread_cleanup_pop_defer_np():
_GNU_SOURCE
Like pthread_cleanup_push(3), pthread_cleanup_push_defer_np() pushes routine onto the thread's stack of cancelation clean-up handlers. In addition, it also saves the thread's current cancelability type, and sets the cancelability type to "deferred" (see pthread_setcanceltype(3)); this ensures that cancelation clean-up will occur even if the thread's cancelability type was "asynchronous" before the call.
Like pthread_cleanup_pop(3), pthread_cleanup_pop_restore_np() pops the top-most clean-up handler from the thread's stack of cancelation clean-up handlers. In addition, it restores the thread's cancelability type to its value at the time of the matching pthread_cleanup_push_defer_np().
呼び出し側では、これらの関数の呼び出しが同じ関数の中で対となり、かつ 文法的に同じネストレベル (nesting level) になることを保証しなければ ならない。 pthread_cleanup_push(3) で説明されている他の制限も 適用される。
以下の一連の呼び出し
pthread_cleanup_push_defer_np(routine, arg); pthread_cleanup_pop_restore_np(execute);
と以下は等価である (但し、上の方がより簡潔で効率的である)。
int oldtype; pthread_cleanup_push(routine, arg); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype); ... pthread_setcanceltype(oldtype, NULL); pthread_cleanup_pop(execute);