214 lines
6.5 KiB
HTML
214 lines
6.5 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
||
|
<title>pthread_test_exit_np()--Test Thread Exit Status</title>
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<!-- Begin Header Records ========================================== -->
|
||
|
<!-- NETMG2 SCRIPT A converted by B2H R4.1 (346) (CMS) by HOLTJM at -->
|
||
|
<!-- RCHVMW2 on 29 Jan 1999 at 10:01:37 -->
|
||
|
<!--File Edited November 2001 --><!--End Header Records -->
|
||
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<!-- Java sync-link -->
|
||
|
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
|
||
|
</script>
|
||
|
|
||
|
<a name="Top_Of_Page"></a>
|
||
|
|
||
|
<h2>pthread_test_exit_np()--Test Thread Exit Status</h2>
|
||
|
|
||
|
<div class="box" style="width: 50%;">
|
||
|
<br>
|
||
|
Syntax:
|
||
|
<pre> #include <pthread.h>
|
||
|
#include <sched.h>
|
||
|
int pthread_test_exit_np(void **status); </pre>
|
||
|
Service Program Name: QP0WPTHR<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE <br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Signal Safe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<p>The pthread_test_exit_np() function returns the current state of the thread along with its exit status.</p>
|
||
|
|
||
|
<p>If the thread is currently processing an exit condition due to a call to <strong>pthread_exit</strong>() or cancellation due to being the target of a <strong>pthread_cancel</strong>(), <strong>pthread_test_exit_np</strong>() returns <strong>PTHREAD_STATUS_EXIT_NP</strong> and sets the exit status pointed to by the status parameter to be the current thread exit status.</p>
|
||
|
|
||
|
<p>If the thread is currently running and is not running cancellation cleanup handlers or data destructors while terminating, <strong>pthread_test_exit_np()</strong> returns <strong>PTHREAD_STATUS_ACTIVE_NP</strong>, and does not return the exit status.</p>
|
||
|
|
||
|
<p><strong>Note:</strong> This function is not portable.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Authorities and Locks</h3>
|
||
|
|
||
|
<p>None.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Parameters</h3>
|
||
|
|
||
|
<dl>
|
||
|
<dt><strong>status</strong></dt>
|
||
|
|
||
|
<dd>Pointer to the parameter to receive the exit status if <em>PTHREAD_STATUS_EXIT_NP</em> is returned</dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
<h3>Return Value</h3>
|
||
|
|
||
|
<dl>
|
||
|
<dt><strong>PTHREAD_STATUS_ACTIVE_NP</strong></dt>
|
||
|
|
||
|
<dd>The thread is currently not exiting.<br><br></dd>
|
||
|
|
||
|
<dt><strong>PTHREAD_STATUS_EXIT_NP</strong></dt>
|
||
|
|
||
|
<dd>The thread is currently exiting.<br><br></dd>
|
||
|
|
||
|
<dt><strong>value</strong></dt>
|
||
|
|
||
|
<dd><strong>pthread_test_exit_np()</strong> was not successful. <em>value</em> is set to indicate the error condition.</dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
<h3>Error Conditions</h3>
|
||
|
|
||
|
<p>If <strong>pthread_test_exit_np()</strong> 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.</p>
|
||
|
|
||
|
<dl>
|
||
|
<dt><em>[EINVAL]</em></dt>
|
||
|
|
||
|
<dd><p>The values specified for the argument are not correct.</p></dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
<h3>Related Information</h3>
|
||
|
|
||
|
<ul>
|
||
|
<li>The <<strong>pthread.h</strong>> header file. See <a href="rzah4hed.htm">Header files for Pthread functions</a>.<br><br></li>
|
||
|
|
||
|
<li><a href="users_39.htm">pthread_cancel()</a>--Cancel Thread<br><br></li>
|
||
|
|
||
|
<li><a href="users_18.htm">pthread_exit()</a>--Terminate Calling Thread</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<h3>Example</h3>
|
||
|
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
|
||
|
for information pertaining to code examples.</p>
|
||
|
<pre>#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;
|
||
|
}</pre>
|
||
|
|
||
|
<p><strong>Output:</strong></p>
|
||
|
|
||
|
<pre>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</pre>
|
||
|
|
||
|
<hr>
|
||
|
API introduced: V4R3
|
||
|
<hr>
|
||
|
<center>
|
||
|
<table cellpadding="2" cellspacing="2">
|
||
|
<tr align="center">
|
||
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> |
|
||
|
<a href="rzah4mst.htm">Pthread APIs</a> |
|
||
|
<a href="aplist.htm">APIs by category</a></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</center>
|
||
|
|
||
|
</body>
|
||
|
</html>
|