#include <pthread.h> #include <sched.h> int pthread_test_exit_np(void **status);Service Program Name: QP0WPTHR
The pthread_test_exit_np() function returns the current state of the thread along with its exit status.
If the thread is currently processing an exit condition due to a call to pthread_exit() or cancellation due to being the target of a pthread_cancel(), pthread_test_exit_np() returns PTHREAD_STATUS_EXIT_NP and sets the exit status pointed to by the status parameter to be the current thread exit status.
If the thread is currently running and is not running cancellation cleanup handlers or data destructors while terminating, pthread_test_exit_np() returns PTHREAD_STATUS_ACTIVE_NP, and does not return the exit status.
Note: This function is not portable.
None.
If pthread_test_exit_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.
The values specified for the argument are not correct.
See Code disclaimer information for information pertaining to code examples.
#define _MULTI_THREADED #include <pthread.h> #include <stdio.h> #include "check.h" int checkStatusFailed1=0; int missedHandler1=1; int thread1Status=42; void cleanupHandler1(void *arg) { int rc; void *status; printf("Thread 1 - cleanup handler\n"); missedHandler1=0; rc = pthread_test_exit_np(&status); if (rc != PTHREAD_STATUS_EXIT_NP) { printf("Thread 1 - returned %d instead " "of PTHREAD_STATUS_EXIT_NP\n", rc); checkStatusFailed1 = 1; return; } if (__INT(status) != thread1Status) { printf("Thread 1 - status = %d\n" "Thread 1 - expected %d\n", __INT(status), thread1Status); checkStatusFailed1=1; } printf("Thread 1 - correctly got PTHREAD_STATUS_EXIT_NP " "and thread exit status of %d\n", thread1Status); } void *thread1func(void *parm) { printf("Thread 1 - Entered\n"); pthread_cleanup_push(cleanupHandler1, NULL); pthread_exit(__VOID(thread1Status)); pthread_cleanup_pop(0); return __VOID(0); } int main(int argc, char **argv) { pthread_t thread; int rc=0; void *status; printf("Enter Testcase - %s\n", argv[0]); rc = pthread_test_exit_np(&status); if (rc != PTHREAD_STATUS_ACTIVE_NP) { printf("We should always be in an ACTIVE status here! rc=%d\n", rc); exit(1); } printf("Create the pthread_exit thread\n"); rc = pthread_create(&thread, NULL, thread1func, NULL); checkResults("pthread_create()\n", rc); rc = pthread_join(thread, &status); checkResults("pthread_join()\n", rc); if (__INT(status) != thread1Status) { printf("Wrong status from thread 1\n"); } if (checkStatusFailed1 || missedHandler1) { printf("The thread did not complete its test correctly! " " check=%d, missed=%d\n", checkStatusFailed1, missedHandler1); exit(1); } printf("Main completed\n"); return 0; }
Output:
Enter Testcase - QP0WTEST/TPTEXIT0 Create the pthread_exit thread Thread 1 - Entered Thread 1 - cleanup handler Thread 1 - correctly got PTHREAD_STATUS_EXIT_NP and thread exit status of 42 Main completed
Top | Pthread APIs | APIs by category |