188 lines
5.6 KiB
HTML
188 lines
5.6 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_cleanup_pop()--Pop Cleanup Handler off of Cancellation Cleanup
|
|
Stack</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_cleanup_pop()--Pop Cleanup Handler off of Cancellation Cleanup
|
|
Stack</h2>
|
|
|
|
<div class="box" style="width: 50%;">
|
|
<br>
|
|
Syntax:
|
|
|
|
<pre>
|
|
#include <pthread.h>
|
|
void pthread_cleanup_pop(int execute);
|
|
</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: No<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p>The <strong>pthread_cleanup_pop</strong>() function pops the last cleanup
|
|
handler from the cancellation cleanup stack. If the <em>execute</em> parameter
|
|
is nonzero, the handler is called with the argument specified by the <strong>
|
|
pthread_cleanup_push</strong>() call with which the handler was registered.</p>
|
|
|
|
<p>The <strong>pthread_cleanup_push</strong>() and the matching <strong>
|
|
pthread_cleanup_pop</strong>() call should be in the same lexical scope (that is,
|
|
same level of brackets {}).</p>
|
|
|
|
<p>When the thread calls <strong>pthread_exit</strong>() or is cancelled by
|
|
<strong>pthread_cancel</strong>(), the cancellation cleanup handlers are called
|
|
with the argument specified by the <strong>pthread_cleanup_push</strong>() call
|
|
that the handler was registered with.</p>
|
|
|
|
<p>During this thread cancellation cleanup, the thread calls cancellation
|
|
cleanup handlers with cancellation disabled until the last cancellation cleanup
|
|
handler returns. The handlers are called in Last In, First Out (LIFO) order.
|
|
Automatic storage for the invocation stack frame of the function that
|
|
registered the handler is still present when the cancellation cleanup handler
|
|
is executed.</p>
|
|
|
|
<p>When a cancellation cleanup handler is called because of a call to <strong>
|
|
pthread_cleanup_pop</strong>(1), the cancellation cleanup handler does not
|
|
necessarily run with cancellation disabled. The cancellation state and
|
|
cancellation type are not changed by a call to <strong>
|
|
pthread_cleanup_pop</strong>(1).</p>
|
|
|
|
<p>A cancellation cleanup handler should not exit using <strong>
|
|
longjmp</strong>() or <strong>siglongjmp</strong>(). If a cleanup handler takes
|
|
an exception, the exception condition is handled and ignored and processing
|
|
continues. You can look in the job log of the job to see exception messages
|
|
generated by cancellation cleanup handlers.</p>
|
|
|
|
<br>
|
|
<h3>Authorities and Locks</h3>
|
|
|
|
<p>None.</p>
|
|
|
|
<br>
|
|
<h3>Parameters</h3>
|
|
|
|
<dl>
|
|
<dt><strong>execute</strong></dt>
|
|
|
|
<dd>(Input) Boolean value indicating whether the cancellation cleanup handler
|
|
should be executed</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Return Value</h3>
|
|
|
|
<p>None.</p>
|
|
|
|
<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_42.htm">pthread_cleanup_push()</a>--Push Cleanup Handler onto
|
|
Cancellation Cleanup Stack<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"
|
|
|
|
void cleanupHandler(void *arg)
|
|
{
|
|
printf("In the cleanup handler\n");
|
|
}
|
|
|
|
void *threadfunc(void *parm)
|
|
{
|
|
printf("Entered secondary thread, you should see the cleanup handler\n");
|
|
pthread_cleanup_push(cleanupHandler, NULL);
|
|
sleep(1); /* Simulate more code here */
|
|
pthread_cleanup_pop(1);
|
|
return NULL;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
pthread_t thread;
|
|
int rc=0;
|
|
|
|
printf("Enter Testcase - %s\n", argv[0]);
|
|
|
|
/* Create a thread using default attributes */
|
|
printf("Create thread using the NULL attributes\n");
|
|
|
|
rc = pthread_create(&thread, NULL, threadfunc, NULL);
|
|
checkResults("pthread_create(NULL)\n", rc);
|
|
|
|
/* sleep() is not a very robust way to wait for the thread */
|
|
sleep(5);
|
|
printf("Main completed\n");
|
|
return 0;
|
|
}
|
|
</pre>
|
|
|
|
<p><strong>Output:</strong></p>
|
|
|
|
<pre>
|
|
Enter Testcase - QP0WTEST/TPCLPO0
|
|
Create thread using the NULL attributes
|
|
Entered secondary thread, you should see the cleanup handler
|
|
In the cleanup handler
|
|
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>
|
|
|