167 lines
6.7 KiB
HTML
167 lines
6.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>pthread_setcancelstate</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="pthread_setcancelstate"></a> <a name="tag_03_568"></a><!-- pthread_setcancelstate -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_568_01"></a>NAME</h4>
|
|
|
|
<blockquote>pthread_setcancelstate, pthread_setcanceltype, pthread_testcancel - set cancelability state</blockquote>
|
|
|
|
<h4><a name="tag_03_568_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<div class="box"><code><tt><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> #include <<a href="../basedefs/pthread.h.html">pthread.h</a>><br>
|
|
<br>
|
|
int pthread_setcancelstate(int</tt> <i>state</i><tt>, int *</tt><i>oldstate</i><tt>);<br>
|
|
int pthread_setcanceltype(int</tt> <i>type</i><tt>, int *</tt><i>oldtype</i><tt>);<br>
|
|
void pthread_testcancel(void); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
|
|
|
|
<tt><br>
|
|
</tt></blockquote>
|
|
|
|
<h4><a name="tag_03_568_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>pthread_setcancelstate</i>() function shall atomically both set the calling thread's cancelability state to the indicated
|
|
<i>state</i> and return the previous cancelability state at the location referenced by <i>oldstate</i>. Legal values for
|
|
<i>state</i> are PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DISABLE.</p>
|
|
|
|
<p>The <i>pthread_setcanceltype</i>() function shall atomically both set the calling thread's cancelability type to the indicated
|
|
<i>type</i> and return the previous cancelability type at the location referenced by <i>oldtype</i>. Legal values for <i>type</i>
|
|
are PTHREAD_CANCEL_DEFERRED and PTHREAD_CANCEL_ASYNCHRONOUS.</p>
|
|
|
|
<p>The cancelability state and type of any newly created threads, including the thread in which <i>main</i>() was first invoked,
|
|
shall be PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DEFERRED respectively.</p>
|
|
|
|
<p>The <i>pthread_testcancel</i>() function shall create a cancelation point in the calling thread. The <i>pthread_testcancel</i>()
|
|
function shall have no effect if cancelability is disabled.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_568_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>If successful, the <i>pthread_setcancelstate</i>() and <i>pthread_setcanceltype</i>() functions shall return zero; otherwise, an
|
|
error number shall be returned to indicate the error.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_568_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>pthread_setcancelstate</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The specified state is not PTHREAD_CANCEL_ENABLE or PTHREAD_CANCEL_DISABLE.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>pthread_setcanceltype</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The specified type is not PTHREAD_CANCEL_DEFERRED or PTHREAD_CANCEL_ASYNCHRONOUS.</dd>
|
|
</dl>
|
|
|
|
<p>These functions shall not return an error code of [EINTR].</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_568_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_568_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_568_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>pthread_setcancelstate</i>() and <i>pthread_setcanceltype</i>() functions control the points at which a thread may be
|
|
asynchronously canceled. For cancelation control to be usable in modular fashion, some rules need to be followed.</p>
|
|
|
|
<p>An object can be considered to be a generalization of a procedure. It is a set of procedures and global variables written as a
|
|
unit and called by clients not known by the object. Objects may depend on other objects.</p>
|
|
|
|
<p>First, cancelability should only be disabled on entry to an object, never explicitly enabled. On exit from an object, the
|
|
cancelability state should always be restored to its value on entry to the object.</p>
|
|
|
|
<p>This follows from a modularity argument: if the client of an object (or the client of an object that uses that object) has
|
|
disabled cancelability, it is because the client does not want to be concerned about cleaning up if the thread is canceled while
|
|
executing some sequence of actions. If an object is called in such a state and it enables cancelability and a cancelation request
|
|
is pending for that thread, then the thread is canceled, contrary to the wish of the client that disabled.</p>
|
|
|
|
<p>Second, the cancelability type may be explicitly set to either <i>deferred</i> or <i>asynchronous</i> upon entry to an object.
|
|
But as with the cancelability state, on exit from an object the cancelability type should always be restored to its value on entry
|
|
to the object.</p>
|
|
|
|
<p>Finally, only functions that are cancel-safe may be called from a thread that is asynchronously cancelable.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_568_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_568_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="pthread_cancel.html"><i>pthread_cancel</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a
|
|
href="../basedefs/pthread.h.html"><i><pthread.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_568_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 5. Included for alignment with the POSIX Threads Extension.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_568_12"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>pthread_setcancelstate</i>(), <i>pthread_setcanceltype</i>(), and <i>pthread_testcancel</i>() functions are marked as
|
|
part of the Threads option.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|