|
Syntax #include <pthread.h> void pthread_cleanup_peek_np(pthread_cleanup_entry_np_t *entry); Threadsafe: Yes Signal Safe: Yes |
The pthread_cleanup_peek_np() function returns a copy of the cleanup handler entry that would be popped via the next call to pthread_cleanup_pop(). The handler remains on the cancelation cleanup stack after the call to pthread_cleanup_peek_np().
During this thread cancelation cleanup processing, the thread invokes cancelation cleanup handlers with cancelation disabled until the last cancelation cleanup handler returns. The handlers are invoked in LIFO (Last In, First Out) order. Automatic storage for the invocation stack frame of the function that registered the handler will still be present when the cancelation cleanup handler is executed.
The pthread_cleanup_push() and the matching pthread_cleanup_pop() call should be in the same lexical scope (i.e. same level of brackets {})
The pthread_cleanup_peek_np() function has no scoping rules.
This function is not portable
None.
None.
If pthread_cleanup_peek_np() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.
#define _MULTI_THREADED
#include <pthread.h>
#include <stdio.h>
#include "check.h"
void cleanupHandler1(void *arg) { printf("In Handler 1\n"); return; }
void cleanupHandler2(void *arg) { printf("In Handler 2\n"); return; }
void cleanupHandler3(void *arg) { printf("In Handler 3\n"); return; }
int args[3] = {0,0,0};
int main(int argc, char **argv)
{
int rc=0;
pthread_cleanup_entry_np_t entry;
printf("Enter Testcase - %s\n", argv[0]);
printf("Check for absence of cleanup handlers\n");
rc = pthread_cleanup_peek_np(&entry);
if (rc != ENOENT) {
printf("pthread_cleanup_peek_np(), expected ENOENT\n");
exit(1);
}
printf("Push some cancelation cleanup handlers\n");
pthread_cleanup_push(cleanupHandler1, &args[0]);
pthread_cleanup_push(cleanupHandler2, &args[1]);
printf("Check for cleanupHandler2\n");
rc = pthread_cleanup_peek_np(&entry);
checkResults("pthread_cleanup_peek_np(2)\n", rc);
if (entry.handler != cleanupHandler2 ||
entry.arg != &args[1]) {
printf("Didn't get expected handler(2) information!\n");
exit(1);
}
pthread_cleanup_push(cleanupHandler3, &args[2]);
printf("Check for cleanupHandler3\n");
rc = pthread_cleanup_peek_np(&entry);
checkResults("pthread_cleanup_peek_np(3)\n", rc);
if (entry.handler != cleanupHandler3 ||
entry.arg != &args[2]) {
printf("Didn't get expected handler(3) information!\n");
exit(1);
}
pthread_cleanup_pop(0);
pthread_cleanup_pop(0);
pthread_cleanup_pop(0);
printf("Main completed\n");
return 0;
}
Output
Enter Testcase - QP0WTEST/TPCLPP0 Check for absence of cleanup handlers Push some cancelation cleanup handlers Check for cleanupHandler2 Check for cleanupHandler3 Main completed