768 lines
45 KiB
HTML
768 lines
45 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>System Interfaces Chapter 2</title>
|
|
</head>
|
|
<body>
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3">
|
|
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001</font></center>
|
|
|
|
<hr size="2" noshade>
|
|
<h3><a name="tag_02_09"></a>Threads</h3>
|
|
|
|
<p><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The functionality described in this section is dependent on support of the Threads option (and the rest of this section is not
|
|
further shaded for this option). <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<p>This section defines functionality to support multiple flows of control, called ``threads'', within a process. For the
|
|
definition of threads, see the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/xbd_chap03.html#tag_03_393">Section 3.393, Thread</a>.</p>
|
|
|
|
<p>The specific functional areas covered by threads and their scope include:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>Thread management: the creation, control, and termination of multiple flows of control in the same process under the assumption
|
|
of a common shared address space</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Synchronization primitives optimized for tightly coupled operation of multiple control flows in a common, shared address
|
|
space</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<h4><a name="tag_02_09_01"></a>Thread-Safety</h4>
|
|
|
|
<p>All functions defined by this volume of IEEE Std 1003.1-2001 shall be thread-safe, except that the following
|
|
functions<a href="#tag_foot_1"><sup><small>1</small></sup></a> need not be thread-safe.</p>
|
|
|
|
<table cellpadding="3">
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/asctime.html"><i>asctime</i>()</a><br>
|
|
<a href="../functions/basename.html"><i>basename</i>()</a><br>
|
|
<a href="../functions/catgets.html"><i>catgets</i>()</a><br>
|
|
<a href="../functions/crypt.html"><i>crypt</i>()</a><br>
|
|
<a href="../functions/ctime.html"><i>ctime</i>()</a><br>
|
|
<a href="../functions/dbm_clearerr.html"><i>dbm_clearerr</i>()</a><br>
|
|
<a href="../functions/dbm_close.html"><i>dbm_close</i>()</a><br>
|
|
<a href="../functions/dbm_delete.html"><i>dbm_delete</i>()</a><br>
|
|
<a href="../functions/dbm_error.html"><i>dbm_error</i>()</a><br>
|
|
<a href="../functions/dbm_fetch.html"><i>dbm_fetch</i>()</a><br>
|
|
<a href="../functions/dbm_firstkey.html"><i>dbm_firstkey</i>()</a><br>
|
|
<a href="../functions/dbm_nextkey.html"><i>dbm_nextkey</i>()</a><br>
|
|
<a href="../functions/dbm_open.html"><i>dbm_open</i>()</a><br>
|
|
<a href="../functions/dbm_store.html"><i>dbm_store</i>()</a><br>
|
|
<a href="../functions/dirname.html"><i>dirname</i>()</a><br>
|
|
<a href="../functions/dlerror.html"><i>dlerror</i>()</a><br>
|
|
<a href="../functions/drand48.html"><i>drand48</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/ecvt.html"><i>ecvt</i>()</a><br>
|
|
<a href="../functions/encrypt.html"><i>encrypt</i>()</a><br>
|
|
<a href="../functions/endgrent.html"><i>endgrent</i>()</a><br>
|
|
<a href="../functions/endpwent.html"><i>endpwent</i>()</a><br>
|
|
<a href="../functions/endutxent.html"><i>endutxent</i>()</a><br>
|
|
<a href="../functions/fcvt.html"><i>fcvt</i>()</a><br>
|
|
<a href="../functions/ftw.html"><i>ftw</i>()</a><br>
|
|
<a href="../functions/gcvt.html"><i>gcvt</i>()</a><br>
|
|
<a href="../functions/getc_unlocked.html"><i>getc_unlocked</i>()</a><br>
|
|
<a href="../functions/getchar_unlocked.html"><i>getchar_unlocked</i>()</a><br>
|
|
<a href="../functions/getdate.html"><i>getdate</i>()</a><br>
|
|
<a href="../functions/getenv.html"><i>getenv</i>()</a><br>
|
|
<a href="../functions/getgrent.html"><i>getgrent</i>()</a><br>
|
|
<a href="../functions/getgrgid.html"><i>getgrgid</i>()</a><br>
|
|
<a href="../functions/getgrnam.html"><i>getgrnam</i>()</a><br>
|
|
<a href="../functions/gethostbyaddr.html"><i>gethostbyaddr</i>()</a><br>
|
|
<a href="../functions/gethostbyname.html"><i>gethostbyname</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/gethostent.html"><i>gethostent</i>()</a><br>
|
|
<a href="../functions/getlogin.html"><i>getlogin</i>()</a><br>
|
|
<a href="../functions/getnetbyaddr.html"><i>getnetbyaddr</i>()</a><br>
|
|
<a href="../functions/getnetbyname.html"><i>getnetbyname</i>()</a><br>
|
|
<a href="../functions/getnetent.html"><i>getnetent</i>()</a><br>
|
|
<a href="../functions/getopt.html"><i>getopt</i>()</a><br>
|
|
<a href="../functions/getprotobyname.html"><i>getprotobyname</i>()</a><br>
|
|
<a href="../functions/getprotobynumber.html"><i>getprotobynumber</i>()</a><br>
|
|
<a href="../functions/getprotoent.html"><i>getprotoent</i>()</a><br>
|
|
<a href="../functions/getpwent.html"><i>getpwent</i>()</a><br>
|
|
<a href="../functions/getpwnam.html"><i>getpwnam</i>()</a><br>
|
|
<a href="../functions/getpwuid.html"><i>getpwuid</i>()</a><br>
|
|
<a href="../functions/getservbyname.html"><i>getservbyname</i>()</a><br>
|
|
<a href="../functions/getservbyport.html"><i>getservbyport</i>()</a><br>
|
|
<a href="../functions/getservent.html"><i>getservent</i>()</a><br>
|
|
<a href="../functions/getutxent.html"><i>getutxent</i>()</a><br>
|
|
<a href="../functions/getutxid.html"><i>getutxid</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/getutxline.html"><i>getutxline</i>()</a><br>
|
|
<a href="../functions/gmtime.html"><i>gmtime</i>()</a><br>
|
|
<a href="../functions/hcreate.html"><i>hcreate</i>()</a><br>
|
|
<a href="../functions/hdestroy.html"><i>hdestroy</i>()</a><br>
|
|
<a href="../functions/hsearch.html"><i>hsearch</i>()</a><br>
|
|
<a href="../functions/inet_ntoa.html"><i>inet_ntoa</i>()</a><br>
|
|
<a href="../functions/l64a.html"><i>l64a</i>()</a><br>
|
|
<a href="../functions/lgamma.html"><i>lgamma</i>()</a><br>
|
|
<a href="../functions/lgammaf.html"><i>lgammaf</i>()</a><br>
|
|
<a href="../functions/lgammal.html"><i>lgammal</i>()</a><br>
|
|
<a href="../functions/localeconv.html"><i>localeconv</i>()</a><br>
|
|
<a href="../functions/localtime.html"><i>localtime</i>()</a><br>
|
|
<a href="../functions/lrand48.html"><i>lrand48</i>()</a><br>
|
|
<a href="../functions/mrand48.html"><i>mrand48</i>()</a><br>
|
|
<a href="../functions/nftw.html"><i>nftw</i>()</a><br>
|
|
<a href="../functions/nl_langinfo.html"><i>nl_langinfo</i>()</a><br>
|
|
<a href="../functions/ptsname.html"><i>ptsname</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/putc_unlocked.html"><i>putc_unlocked</i>()</a><br>
|
|
<a href="../functions/putchar_unlocked.html"><i>putchar_unlocked</i>()</a><br>
|
|
<a href="../functions/putenv.html"><i>putenv</i>()</a><br>
|
|
<a href="../functions/pututxline.html"><i>pututxline</i>()</a><br>
|
|
<a href="../functions/rand.html"><i>rand</i>()</a><br>
|
|
<a href="../functions/readdir.html"><i>readdir</i>()</a><br>
|
|
<a href="../functions/setenv.html"><i>setenv</i>()</a><br>
|
|
<a href="../functions/setgrent.html"><i>setgrent</i>()</a><br>
|
|
<a href="../functions/setkey.html"><i>setkey</i>()</a><br>
|
|
<a href="../functions/setpwent.html"><i>setpwent</i>()</a><br>
|
|
<a href="../functions/setutxent.html"><i>setutxent</i>()</a><br>
|
|
<a href="../functions/strerror.html"><i>strerror</i>()</a><br>
|
|
<a href="../functions/strtok.html"><i>strtok</i>()</a><br>
|
|
<a href="../functions/ttyname.html"><i>ttyname</i>()</a><br>
|
|
<a href="../functions/unsetenv.html"><i>unsetenv</i>()</a><br>
|
|
<a href="../functions/wcstombs.html"><i>wcstombs</i>()</a><br>
|
|
<a href="../functions/wctomb.html"><i>wctomb</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>The <a href="../functions/ctermid.html"><i>ctermid</i>()</a> and <a href="../functions/tmpnam.html"><i>tmpnam</i>()</a>
|
|
functions need not be thread-safe if passed a NULL argument. The <a href="../functions/wcrtomb.html"><i>wcrtomb</i>()</a> and <a
|
|
href="../functions/wcsrtombs.html"><i>wcsrtombs</i>()</a> functions need not be thread-safe if passed a NULL <i>ps</i>
|
|
argument.</p>
|
|
|
|
<p>Implementations shall provide internal synchronization as necessary in order to satisfy this requirement.</p>
|
|
|
|
<h4><a name="tag_02_09_02"></a>Thread IDs</h4>
|
|
|
|
<p>Although implementations may have thread IDs that are unique in a system, applications should only assume that thread IDs are
|
|
usable and unique within a single process. The effect of calling any of the functions defined in this volume of
|
|
IEEE Std 1003.1-2001 and passing as an argument the thread ID of a thread from another process is unspecified. A
|
|
conforming implementation is free to reuse a thread ID after the thread terminates if it was created with the <i>detachstate</i>
|
|
attribute set to PTHREAD_CREATE_DETACHED or if <a href="../functions/pthread_detach.html"><i>pthread_detach</i>()</a> or <a href=
|
|
"../functions/pthread_join.html"><i>pthread_join</i>()</a> has been called for that thread. If a thread is detached, its thread ID
|
|
is invalid for use as an argument in a call to <a href="../functions/pthread_detach.html"><i>pthread_detach</i>()</a> or <a href=
|
|
"../functions/pthread_join.html"><i>pthread_join</i>()</a>.</p>
|
|
|
|
<h4><a name="tag_02_09_03"></a>Thread Mutexes</h4>
|
|
|
|
<p>A thread that has blocked shall not prevent any unblocked thread that is eligible to use the same processing resources from
|
|
eventually making forward progress in its execution. Eligibility for processing resources is determined by the scheduling
|
|
policy.</p>
|
|
|
|
<p>A thread shall become the owner of a mutex, <i>m</i>, when one of the following occurs:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>It returns successfully from <a href="../functions/pthread_mutex_lock.html"><i>pthread_mutex_lock</i>()</a> with <i>m</i> as the
|
|
<i>mutex</i> argument.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>It returns successfully from <a href="../functions/pthread_mutex_trylock.html"><i>pthread_mutex_trylock</i>()</a> with <i>m</i>
|
|
as the <i>mutex</i> argument.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p><sup>[<a href="javascript:open_code('TMO')">TMO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
It returns successfully from <a href="../functions/pthread_mutex_timedlock.html"><i>pthread_mutex_timedlock</i>()</a> with <i>m</i>
|
|
as the mutex argument. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>It returns (successfully or not) from <a href="../functions/pthread_cond_wait.html"><i>pthread_cond_wait</i>()</a> with <i>m</i>
|
|
as the <i>mutex</i> argument (except as explicitly indicated otherwise for certain errors).</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>It returns (successfully or not) from <a href="../functions/pthread_cond_timedwait.html"><i>pthread_cond_timedwait</i>()</a>
|
|
with <i>m</i> as the <i>mutex</i> argument (except as explicitly indicated otherwise for certain errors).</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The thread shall remain the owner of <i>m</i> until one of the following occurs:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>It executes <a href="../functions/pthread_mutex_unlock.html"><i>pthread_mutex_unlock</i>()</a> with <i>m</i> as the <i>mutex</i>
|
|
argument</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>It blocks in a call to <a href="../functions/pthread_cond_wait.html"><i>pthread_cond_wait</i>()</a> with <i>m</i> as the
|
|
<i>mutex</i> argument.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>It blocks in a call to <a href="../functions/pthread_cond_timedwait.html"><i>pthread_cond_timedwait</i>()</a> with <i>m</i> as
|
|
the <i>mutex</i> argument.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The implementation shall behave as if at all times there is at most one owner of any mutex.</p>
|
|
|
|
<p>A thread that becomes the owner of a mutex is said to have ``acquired'' the mutex and the mutex is said to have become
|
|
``locked''; when a thread gives up ownership of a mutex it is said to have ``released'' the mutex and the mutex is said to have
|
|
become ``unlocked''.</p>
|
|
|
|
<h4><a name="tag_02_09_04"></a>Thread Scheduling</h4>
|
|
|
|
<p><sup>[<a href="javascript:open_code('TPS')">TPS</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The functionality described in this section is dependent on support of the Thread Execution Scheduling option (and the rest of this
|
|
section is not further marked for this option). <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<h5><a name="tag_02_09_04_01"></a>Thread Scheduling Attributes</h5>
|
|
|
|
<p>In support of the scheduling function, threads have attributes which are accessed through the <b>pthread_attr_t</b> thread
|
|
creation attributes object.</p>
|
|
|
|
<p>The <i>contentionscope</i> attribute defines the scheduling contention scope of the thread to be either PTHREAD_SCOPE_PROCESS or
|
|
PTHREAD_SCOPE_SYSTEM.</p>
|
|
|
|
<p>The <i>inheritsched</i> attribute specifies whether a newly created thread is to inherit the scheduling attributes of the
|
|
creating thread or to have its scheduling values set according to the other scheduling attributes in the <b>pthread_attr_t</b>
|
|
object.</p>
|
|
|
|
<p>The <i>schedpolicy</i> attribute defines the scheduling policy for the thread. The <i>schedparam</i> attribute defines the
|
|
scheduling parameters for the thread. The interaction of threads having different policies within a process is described as part of
|
|
the definition of those policies.</p>
|
|
|
|
<p>If the Thread Execution Scheduling option is defined, and the <i>schedpolicy</i> attribute specifies one of the priority-based
|
|
policies defined under this option, the <i>schedparam</i> attribute contains the scheduling priority of the thread. A conforming
|
|
implementation ensures that the priority value in <i>schedparam</i> is in the range associated with the scheduling policy when the
|
|
thread attributes object is used to create a thread, or when the scheduling attributes of a thread are dynamically modified. The
|
|
meaning of the priority value in <i>schedparam</i> is the same as that of <i>priority</i>.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('TSP')">TSP</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If _POSIX_THREAD_SPORADIC_SERVER is defined, the <i>schedparam</i> attribute supports four new members that are used for the
|
|
sporadic server scheduling policy. These members are <i>sched_ss_low_priority</i>, <i>sched_ss_repl_period</i>,
|
|
<i>sched_ss_init_budget</i>, and <i>sched_ss_max_repl</i>. The meaning of these attributes is the same as in the definitions that
|
|
appear under <a href="xsh_chap02_08.html#tag_02_08_04"><i>Process Scheduling</i></a> . <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></p>
|
|
|
|
<p>When a process is created, its single thread has a scheduling policy and associated attributes equal to the process' policy and
|
|
attributes. The default scheduling contention scope value is implementation-defined. The default values of other scheduling
|
|
attributes are implementation-defined.</p>
|
|
|
|
<h5><a name="tag_02_09_04_02"></a>Thread Scheduling Contention Scope</h5>
|
|
|
|
<p>The scheduling contention scope of a thread defines the set of threads with which the thread competes for use of the processing
|
|
resources. The scheduling operation selects at most one thread to execute on each processor at any point in time and the thread's
|
|
scheduling attributes (for example, <i>priority</i>), whether under process scheduling contention scope or system scheduling
|
|
contention scope, are the parameters used to determine the scheduling decision.</p>
|
|
|
|
<p>The scheduling contention scope, in the context of scheduling a mixed scope environment, affects threads as follows:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>A thread created with PTHREAD_SCOPE_SYSTEM scheduling contention scope contends for resources with all other threads in the same
|
|
scheduling allocation domain relative to their system scheduling attributes. The system scheduling attributes of a thread created
|
|
with PTHREAD_SCOPE_SYSTEM scheduling contention scope are the scheduling attributes with which the thread was created. The system
|
|
scheduling attributes of a thread created with PTHREAD_SCOPE_PROCESS scheduling contention scope are the implementation-defined
|
|
mapping into system attribute space of the scheduling attributes with which the thread was created.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Threads created with PTHREAD_SCOPE_PROCESS scheduling contention scope contend directly with other threads within their process
|
|
that were created with PTHREAD_SCOPE_PROCESS scheduling contention scope. The contention is resolved based on the threads'
|
|
scheduling attributes and policies. It is unspecified how such threads are scheduled relative to threads in other processes or
|
|
threads with PTHREAD_SCOPE_SYSTEM scheduling contention scope.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Conforming implementations shall support the PTHREAD_SCOPE_PROCESS scheduling contention scope, the PTHREAD_SCOPE_SYSTEM
|
|
scheduling contention scope, or both.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<h5><a name="tag_02_09_04_03"></a>Scheduling Allocation Domain</h5>
|
|
|
|
<p>Implementations shall support scheduling allocation domains containing one or more processors. It should be noted that the
|
|
presence of multiple processors does not automatically indicate a scheduling allocation domain size greater than one. Conforming
|
|
implementations on multi-processors may map all or any subset of the CPUs to one or multiple scheduling allocation domains, and
|
|
could define these scheduling allocation domains on a per-thread, per-process, or per-system basis, depending on the types of
|
|
applications intended to be supported by the implementation. The scheduling allocation domain is independent of scheduling
|
|
contention scope, as the scheduling contention scope merely defines the set of threads with which a thread contends for processor
|
|
resources, while scheduling allocation domain defines the set of processors for which it contends. The semantics of how this
|
|
contention is resolved among threads for processors is determined by the scheduling policies of the threads.</p>
|
|
|
|
<p>The choice of scheduling allocation domain size and the level of application control over scheduling allocation domains is
|
|
implementation-defined. Conforming implementations may change the size of scheduling allocation domains and the binding of threads
|
|
to scheduling allocation domains at any time.</p>
|
|
|
|
<p>For application threads with scheduling allocation domains of size equal to one, the scheduling rules defined for SCHED_FIFO and
|
|
SCHED_RR shall be used; see <a href="xsh_chap02_08.html#tag_02_08_04_01"><i>Scheduling Policies</i></a> . All threads with system
|
|
scheduling contention scope, regardless of the processes in which they reside, compete for the processor according to their
|
|
priorities. Threads with process scheduling contention scope compete only with other threads with process scheduling contention
|
|
scope within their process.</p>
|
|
|
|
<p>For application threads with scheduling allocation domains of size greater than one, the rules defined for SCHED_FIFO, SCHED_RR,
|
|
<sup>[<a href="javascript:open_code('TSP')">TSP</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
and SCHED_SPORADIC <img src="../images/opt-end.gif" alt="[Option End]" border="0"> shall be used in an implementation-defined
|
|
manner. Each thread with system scheduling contention scope competes for the processors in its scheduling allocation domain in an
|
|
implementation-defined manner according to its priority. Threads with process scheduling contention scope are scheduled relative to
|
|
other threads within the same scheduling contention scope in the process.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('TSP')">TSP</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If _POSIX_THREAD_SPORADIC_SERVER is defined, the rules defined for SCHED_SPORADIC in <a href=
|
|
"xsh_chap02_08.html#tag_02_08_04_01"><i>Scheduling Policies</i></a> shall be used in an implementation-defined manner for
|
|
application threads whose scheduling allocation domain size is greater than one. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></p>
|
|
|
|
<h5><a name="tag_02_09_04_04"></a>Scheduling Documentation</h5>
|
|
|
|
<p>If _POSIX_PRIORITY_SCHEDULING is defined, then any scheduling policies beyond SCHED_OTHER, SCHED_FIFO, SCHED_RR, <sup>[<a href=
|
|
"javascript:open_code('TSP')">TSP</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and
|
|
SCHED_SPORADIC, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> as well as the effects of the scheduling policies
|
|
indicated by these other values, and the attributes required in order to support such a policy, are implementation-defined.
|
|
Furthermore, the implementation shall document the effect of all processor scheduling allocation domain values supported for these
|
|
policies.</p>
|
|
|
|
<h4><a name="tag_02_09_05"></a>Thread Cancelation</h4>
|
|
|
|
<p>The thread cancelation mechanism allows a thread to terminate the execution of any other thread in the process in a controlled
|
|
manner. The target thread (that is, the one that is being canceled) is allowed to hold cancelation requests pending in a number of
|
|
ways and to perform application-specific cleanup processing when the notice of cancelation is acted upon.</p>
|
|
|
|
<p>Cancelation is controlled by the cancelation control functions. Each thread maintains its own cancelability state. Cancelation
|
|
may only occur at cancelation points or when the thread is asynchronously cancelable.</p>
|
|
|
|
<p>The thread cancelation mechanism described in this section depends upon programs having set <i>deferred</i> cancelability state,
|
|
which is specified as the default. Applications shall also carefully follow static lexical scoping rules in their execution
|
|
behavior. For example, use of <a href="../functions/setjmp.html"><i>setjmp</i>()</a>, <i>return</i>, <i>goto</i>, and so on, to
|
|
leave user-defined cancelation scopes without doing the necessary scope pop operation results in undefined behavior.</p>
|
|
|
|
<p>Use of asynchronous cancelability while holding resources which potentially need to be released may result in resource loss.
|
|
Similarly, cancelation scopes may only be safely manipulated (pushed and popped) when the thread is in the <i>deferred</i> or
|
|
<i>disabled</i> cancelability states.</p>
|
|
|
|
<h5><a name="tag_02_09_05_01"></a>Cancelability States</h5>
|
|
|
|
<p>The cancelability state of a thread determines the action taken upon receipt of a cancelation request. The thread may control
|
|
cancelation in a number of ways.</p>
|
|
|
|
<p>Each thread maintains its own cancelability state, which may be encoded in two bits:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>Cancelability-Enable: When cancelability is PTHREAD_CANCEL_DISABLE (as defined in the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/pthread.h.html"><i><pthread.h></i></a>), cancelation requests against
|
|
the target thread are held pending. By default, cancelability is set to PTHREAD_CANCEL_ENABLE (as defined in <a href=
|
|
"../basedefs/pthread.h.html"><i><pthread.h></i></a>).</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>Cancelability Type: When cancelability is enabled and the cancelability type is PTHREAD_CANCEL_ASYNCHRONOUS (as defined in <a
|
|
href="../basedefs/pthread.h.html"><i><pthread.h></i></a>), new or pending cancelation requests may be acted upon at any time.
|
|
When cancelability is enabled and the cancelability type is PTHREAD_CANCEL_DEFERRED (as defined in <a href=
|
|
"../basedefs/pthread.h.html"><i><pthread.h></i></a>), cancelation requests are held pending until a cancelation point (see
|
|
below) is reached. If cancelability is disabled, the setting of the cancelability type has no immediate effect as all cancelation
|
|
requests are held pending; however, once cancelability is enabled again the new type is in effect. The cancelability type is
|
|
PTHREAD_CANCEL_DEFERRED in all newly created threads including the thread in which <i>main</i>() was first invoked.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<h5><a name="tag_02_09_05_02"></a>Cancelation Points</h5>
|
|
|
|
<p>Cancelation points shall occur when a thread is executing the following functions:</p>
|
|
|
|
<table cellpadding="3">
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/accept.html"><i>accept</i>()</a><br>
|
|
<a href="../functions/aio_suspend.html"><i>aio_suspend</i>()</a><br>
|
|
<a href="../functions/clock_nanosleep.html"><i>clock_nanosleep</i>()</a><br>
|
|
<a href="../functions/close.html"><i>close</i>()</a><br>
|
|
<a href="../functions/connect.html"><i>connect</i>()</a><br>
|
|
<a href="../functions/creat.html"><i>creat</i>()</a><br>
|
|
<a href="../functions/fcntl.html"><i>fcntl</i>()</a><a href="#tag_foot_2"><sup><small>2</small></sup></a><br>
|
|
<a href="../functions/fsync.html"><i>fsync</i>()</a><br>
|
|
<a href="../functions/getmsg.html"><i>getmsg</i>()</a><br>
|
|
<a href="../functions/getpmsg.html"><i>getpmsg</i>()</a><br>
|
|
<a href="../functions/lockf.html"><i>lockf</i>()</a><br>
|
|
<a href="../functions/mq_receive.html"><i>mq_receive</i>()</a><br>
|
|
<a href="../functions/mq_send.html"><i>mq_send</i>()</a><br>
|
|
<a href="../functions/mq_timedreceive.html"><i>mq_timedreceive</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/mq_timedsend.html"><i>mq_timedsend</i>()</a><br>
|
|
<a href="../functions/msgrcv.html"><i>msgrcv</i>()</a><br>
|
|
<a href="../functions/msgsnd.html"><i>msgsnd</i>()</a><br>
|
|
<a href="../functions/msync.html"><i>msync</i>()</a><br>
|
|
<a href="../functions/nanosleep.html"><i>nanosleep</i>()</a><br>
|
|
<a href="../functions/open.html"><i>open</i>()</a><br>
|
|
<a href="../functions/pause.html"><i>pause</i>()</a><br>
|
|
<a href="../functions/poll.html"><i>poll</i>()</a><br>
|
|
<a href="../functions/pread.html"><i>pread</i>()</a><br>
|
|
<a href="../functions/pthread_cond_timedwait.html"><i>pthread_cond_timedwait</i>()</a><br>
|
|
<a href="../functions/pthread_cond_wait.html"><i>pthread_cond_wait</i>()</a><br>
|
|
<a href="../functions/pthread_join.html"><i>pthread_join</i>()</a><br>
|
|
<a href="../functions/pthread_testcancel.html"><i>pthread_testcancel</i>()</a><br>
|
|
<a href="../functions/putmsg.html"><i>putmsg</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/putpmsg.html"><i>putpmsg</i>()</a><br>
|
|
<a href="../functions/pwrite.html"><i>pwrite</i>()</a><br>
|
|
<a href="../functions/read.html"><i>read</i>()</a><br>
|
|
<a href="../functions/readv.html"><i>readv</i>()</a><br>
|
|
<a href="../functions/recv.html"><i>recv</i>()</a><br>
|
|
<a href="../functions/recvfrom.html"><i>recvfrom</i>()</a><br>
|
|
<a href="../functions/recvmsg.html"><i>recvmsg</i>()</a><br>
|
|
<a href="../functions/select.html"><i>select</i>()</a><br>
|
|
<a href="../functions/sem_timedwait.html"><i>sem_timedwait</i>()</a><br>
|
|
<a href="../functions/sem_wait.html"><i>sem_wait</i>()</a><br>
|
|
<a href="../functions/send.html"><i>send</i>()</a><br>
|
|
<a href="../functions/sendmsg.html"><i>sendmsg</i>()</a><br>
|
|
<a href="../functions/sendto.html"><i>sendto</i>()</a><br>
|
|
<a href="../functions/sigpause.html"><i>sigpause</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/sigsuspend.html"><i>sigsuspend</i>()</a><br>
|
|
<a href="../functions/sigtimedwait.html"><i>sigtimedwait</i>()</a><br>
|
|
<a href="../functions/sigwait.html"><i>sigwait</i>()</a><br>
|
|
<a href="../functions/sigwaitinfo.html"><i>sigwaitinfo</i>()</a><br>
|
|
<a href="../functions/sleep.html"><i>sleep</i>()</a><br>
|
|
<a href="../functions/system.html"><i>system</i>()</a><br>
|
|
<a href="../functions/tcdrain.html"><i>tcdrain</i>()</a><br>
|
|
<a href="../functions/usleep.html"><i>usleep</i>()</a><br>
|
|
<a href="../functions/wait.html"><i>wait</i>()</a><br>
|
|
<a href="../functions/waitid.html"><i>waitid</i>()</a><br>
|
|
<a href="../functions/waitpid.html"><i>waitpid</i>()</a><br>
|
|
<a href="../functions/write.html"><i>write</i>()</a><br>
|
|
<a href="../functions/writev.html"><i>writev</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<hr>
|
|
<p>A cancelation point may also occur when a thread is executing the following functions:</p>
|
|
|
|
<table cellpadding="3">
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/catclose.html"><i>catclose</i>()</a><br>
|
|
<a href="../functions/catgets.html"><i>catgets</i>()</a><br>
|
|
<a href="../functions/catopen.html"><i>catopen</i>()</a><br>
|
|
<a href="../functions/closedir.html"><i>closedir</i>()</a><br>
|
|
<a href="../functions/closelog.html"><i>closelog</i>()</a><br>
|
|
<a href="../functions/ctermid.html"><i>ctermid</i>()</a><br>
|
|
<a href="../functions/dbm_close.html"><i>dbm_close</i>()</a><br>
|
|
<a href="../functions/dbm_delete.html"><i>dbm_delete</i>()</a><br>
|
|
<a href="../functions/dbm_fetch.html"><i>dbm_fetch</i>()</a><br>
|
|
<a href="../functions/dbm_nextkey.html"><i>dbm_nextkey</i>()</a><br>
|
|
<a href="../functions/dbm_open.html"><i>dbm_open</i>()</a><br>
|
|
<a href="../functions/dbm_store.html"><i>dbm_store</i>()</a><br>
|
|
<a href="../functions/dlclose.html"><i>dlclose</i>()</a><br>
|
|
<a href="../functions/dlopen.html"><i>dlopen</i>()</a><br>
|
|
<a href="../functions/endgrent.html"><i>endgrent</i>()</a><br>
|
|
<a href="../functions/endhostent.html"><i>endhostent</i>()</a><br>
|
|
<a href="../functions/endnetent.html"><i>endnetent</i>()</a><br>
|
|
<a href="../functions/endprotoent.html"><i>endprotoent</i>()</a><br>
|
|
<a href="../functions/endpwent.html"><i>endpwent</i>()</a><br>
|
|
<a href="../functions/endservent.html"><i>endservent</i>()</a><br>
|
|
<a href="../functions/endutxent.html"><i>endutxent</i>()</a><br>
|
|
<a href="../functions/fclose.html"><i>fclose</i>()</a><br>
|
|
<a href="../functions/fcntl.html"><i>fcntl</i>()</a><a href="#tag_foot_3"><sup><small>3</small></sup></a><br>
|
|
<a href="../functions/fflush.html"><i>fflush</i>()</a><br>
|
|
<a href="../functions/fgetc.html"><i>fgetc</i>()</a><br>
|
|
<a href="../functions/fgetpos.html"><i>fgetpos</i>()</a><br>
|
|
<a href="../functions/fgets.html"><i>fgets</i>()</a><br>
|
|
<a href="../functions/fgetwc.html"><i>fgetwc</i>()</a><br>
|
|
<a href="../functions/fgetws.html"><i>fgetws</i>()</a><br>
|
|
<a href="../functions/fopen.html"><i>fopen</i>()</a><br>
|
|
<a href="../functions/fprintf.html"><i>fprintf</i>()</a><br>
|
|
<a href="../functions/fputc.html"><i>fputc</i>()</a><br>
|
|
<a href="../functions/fputs.html"><i>fputs</i>()</a><br>
|
|
<a href="../functions/fputwc.html"><i>fputwc</i>()</a><br>
|
|
<a href="../functions/fputws.html"><i>fputws</i>()</a><br>
|
|
<a href="../functions/fread.html"><i>fread</i>()</a><br>
|
|
<a href="../functions/freopen.html"><i>freopen</i>()</a><br>
|
|
<a href="../functions/fscanf.html"><i>fscanf</i>()</a><br>
|
|
<a href="../functions/fseek.html"><i>fseek</i>()</a><br>
|
|
<a href="../functions/fseeko.html"><i>fseeko</i>()</a><br>
|
|
<a href="../functions/fsetpos.html"><i>fsetpos</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/ftell.html"><i>ftell</i>()</a><br>
|
|
<a href="../functions/ftello.html"><i>ftello</i>()</a><br>
|
|
<a href="../functions/ftw.html"><i>ftw</i>()</a><br>
|
|
<a href="../functions/fwprintf.html"><i>fwprintf</i>()</a><br>
|
|
<a href="../functions/fwrite.html"><i>fwrite</i>()</a><br>
|
|
<a href="../functions/fwscanf.html"><i>fwscanf</i>()</a><br>
|
|
<a href="../functions/getc.html"><i>getc</i>()</a><br>
|
|
<a href="../functions/getc_unlocked.html"><i>getc_unlocked</i>()</a><br>
|
|
<a href="../functions/getchar.html"><i>getchar</i>()</a><br>
|
|
<a href="../functions/getchar_unlocked.html"><i>getchar_unlocked</i>()</a><br>
|
|
<a href="../functions/getcwd.html"><i>getcwd</i>()</a><br>
|
|
<a href="../functions/getdate.html"><i>getdate</i>()</a><br>
|
|
<a href="../functions/getgrent.html"><i>getgrent</i>()</a><br>
|
|
<a href="../functions/getgrgid.html"><i>getgrgid</i>()</a><br>
|
|
<a href="../functions/getgrgid_r.html"><i>getgrgid_r</i>()</a><br>
|
|
<a href="../functions/getgrnam.html"><i>getgrnam</i>()</a><br>
|
|
<a href="../functions/getgrnam_r.html"><i>getgrnam_r</i>()</a><br>
|
|
<a href="../functions/gethostbyaddr.html"><i>gethostbyaddr</i>()</a><br>
|
|
<a href="../functions/gethostbyname.html"><i>gethostbyname</i>()</a><br>
|
|
<a href="../functions/gethostent.html"><i>gethostent</i>()</a><br>
|
|
<a href="../functions/gethostname.html"><i>gethostname</i>()</a><br>
|
|
<a href="../functions/getlogin.html"><i>getlogin</i>()</a><br>
|
|
<a href="../functions/getlogin_r.html"><i>getlogin_r</i>()</a><br>
|
|
<a href="../functions/getnetbyaddr.html"><i>getnetbyaddr</i>()</a><br>
|
|
<a href="../functions/getnetbyname.html"><i>getnetbyname</i>()</a><br>
|
|
<a href="../functions/getnetent.html"><i>getnetent</i>()</a><br>
|
|
<a href="../functions/getprotobyname.html"><i>getprotobyname</i>()</a><br>
|
|
<a href="../functions/getprotobynumber.html"><i>getprotobynumber</i>()</a><br>
|
|
<a href="../functions/getprotoent.html"><i>getprotoent</i>()</a><br>
|
|
<a href="../functions/getpwent.html"><i>getpwent</i>()</a><br>
|
|
<a href="../functions/getpwnam.html"><i>getpwnam</i>()</a><br>
|
|
<a href="../functions/getpwnam_r.html"><i>getpwnam_r</i>()</a><br>
|
|
<a href="../functions/getpwuid.html"><i>getpwuid</i>()</a><br>
|
|
<a href="../functions/getpwuid_r.html"><i>getpwuid_r</i>()</a><br>
|
|
<a href="../functions/gets.html"><i>gets</i>()</a><br>
|
|
<a href="../functions/getservbyname.html"><i>getservbyname</i>()</a><br>
|
|
<a href="../functions/getservbyport.html"><i>getservbyport</i>()</a><br>
|
|
<a href="../functions/getservent.html"><i>getservent</i>()</a><br>
|
|
<a href="../functions/getutxent.html"><i>getutxent</i>()</a><br>
|
|
<a href="../functions/getutxid.html"><i>getutxid</i>()</a><br>
|
|
<a href="../functions/getutxline.html"><i>getutxline</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/getwc.html"><i>getwc</i>()</a><br>
|
|
<a href="../functions/getwchar.html"><i>getwchar</i>()</a><br>
|
|
<a href="../functions/getwd.html"><i>getwd</i>()</a><br>
|
|
<a href="../functions/glob.html"><i>glob</i>()</a><br>
|
|
<a href="../functions/iconv_close.html"><i>iconv_close</i>()</a><br>
|
|
<a href="../functions/iconv_open.html"><i>iconv_open</i>()</a><br>
|
|
<a href="../functions/ioctl.html"><i>ioctl</i>()</a><br>
|
|
<a href="../functions/lseek.html"><i>lseek</i>()</a><br>
|
|
<a href="../functions/mkstemp.html"><i>mkstemp</i>()</a><br>
|
|
<a href="../functions/nftw.html"><i>nftw</i>()</a><br>
|
|
<a href="../functions/opendir.html"><i>opendir</i>()</a><br>
|
|
<a href="../functions/openlog.html"><i>openlog</i>()</a><br>
|
|
<a href="../functions/pclose.html"><i>pclose</i>()</a><br>
|
|
<a href="../functions/perror.html"><i>perror</i>()</a><br>
|
|
<a href="../functions/popen.html"><i>popen</i>()</a><br>
|
|
<a href="../functions/posix_fadvise.html"><i>posix_fadvise</i>()</a><br>
|
|
<a href="../functions/posix_fallocate.html"><i>posix_fallocate</i>()</a><br>
|
|
<a href="../functions/posix_madvise.html"><i>posix_madvise</i>()</a><br>
|
|
<a href="../functions/posix_spawn.html"><i>posix_spawn</i>()</a><br>
|
|
<a href="../functions/posix_spawnp.html"><i>posix_spawnp</i>()</a><br>
|
|
<a href="../functions/posix_trace_clear.html"><i>posix_trace_clear</i>()</a><br>
|
|
<a href="../functions/posix_trace_close.html"><i>posix_trace_close</i>()</a><br>
|
|
<a href="../functions/posix_trace_create.html"><i>posix_trace_create</i>()</a><br>
|
|
<a href="../functions/posix_trace_create_withlog.html"><i>posix_trace_create_withlog</i>()</a><br>
|
|
<a href="../functions/posix_trace_eventtypelist_getnext_id.html"><i>posix_trace_eventtypelist_getnext_id</i>()</a><br>
|
|
<a href="../functions/posix_trace_eventtypelist_rewind.html"><i>posix_trace_eventtypelist_rewind</i>()</a><br>
|
|
<a href="../functions/posix_trace_flush.html"><i>posix_trace_flush</i>()</a><br>
|
|
<a href="../functions/posix_trace_get_attr.html"><i>posix_trace_get_attr</i>()</a><br>
|
|
<a href="../functions/posix_trace_get_filter.html"><i>posix_trace_get_filter</i>()</a><br>
|
|
<a href="../functions/posix_trace_get_status.html"><i>posix_trace_get_status</i>()</a><br>
|
|
<a href="../functions/posix_trace_getnext_event.html"><i>posix_trace_getnext_event</i>()</a><br>
|
|
<a href="../functions/posix_trace_open.html"><i>posix_trace_open</i>()</a><br>
|
|
<a href="../functions/posix_trace_rewind.html"><i>posix_trace_rewind</i>()</a><br>
|
|
<a href="../functions/posix_trace_set_filter.html"><i>posix_trace_set_filter</i>()</a><br>
|
|
<a href="../functions/posix_trace_shutdown.html"><i>posix_trace_shutdown</i>()</a><br>
|
|
<a href="../functions/posix_trace_timedgetnext_event.html"><i>posix_trace_timedgetnext_event</i>()</a><br>
|
|
<a href="../functions/posix_typed_mem_open.html"><i>posix_typed_mem_open</i>()</a><br>
|
|
<a href="../functions/printf.html"><i>printf</i>()</a><br>
|
|
<a href="../functions/pthread_rwlock_rdlock.html"><i>pthread_rwlock_rdlock</i>()</a><br>
|
|
<a href="../functions/pthread_rwlock_timedrdlock.html"><i>pthread_rwlock_timedrdlock</i>()</a><br>
|
|
<a href="../functions/pthread_rwlock_timedwrlock.html"><i>pthread_rwlock_timedwrlock</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent"><br>
|
|
<a href="../functions/pthread_rwlock_wrlock.html"><i>pthread_rwlock_wrlock</i>()</a><br>
|
|
<a href="../functions/putc.html"><i>putc</i>()</a><br>
|
|
<a href="../functions/putc_unlocked.html"><i>putc_unlocked</i>()</a><br>
|
|
<a href="../functions/putchar.html"><i>putchar</i>()</a><br>
|
|
<a href="../functions/putchar_unlocked.html"><i>putchar_unlocked</i>()</a><br>
|
|
<a href="../functions/puts.html"><i>puts</i>()</a><br>
|
|
<a href="../functions/pututxline.html"><i>pututxline</i>()</a><br>
|
|
<a href="../functions/putwc.html"><i>putwc</i>()</a><br>
|
|
<a href="../functions/putwchar.html"><i>putwchar</i>()</a><br>
|
|
<a href="../functions/readdir.html"><i>readdir</i>()</a><br>
|
|
<a href="../functions/readdir_r.html"><i>readdir_r</i>()</a><br>
|
|
<a href="../functions/remove.html"><i>remove</i>()</a><br>
|
|
<a href="../functions/rename.html"><i>rename</i>()</a><br>
|
|
<a href="../functions/rewind.html"><i>rewind</i>()</a><br>
|
|
<a href="../functions/rewinddir.html"><i>rewinddir</i>()</a><br>
|
|
<a href="../functions/scanf.html"><i>scanf</i>()</a><br>
|
|
<a href="../functions/seekdir.html"><i>seekdir</i>()</a><br>
|
|
<a href="../functions/semop.html"><i>semop</i>()</a><br>
|
|
<a href="../functions/setgrent.html"><i>setgrent</i>()</a><br>
|
|
<a href="../functions/sethostent.html"><i>sethostent</i>()</a><br>
|
|
<a href="../functions/setnetent.html"><i>setnetent</i>()</a><br>
|
|
<a href="../functions/setprotoent.html"><i>setprotoent</i>()</a><br>
|
|
<a href="../functions/setpwent.html"><i>setpwent</i>()</a><br>
|
|
<a href="../functions/setservent.html"><i>setservent</i>()</a><br>
|
|
<a href="../functions/setutxent.html"><i>setutxent</i>()</a><br>
|
|
<a href="../functions/strerror.html"><i>strerror</i>()</a><br>
|
|
<a href="../functions/syslog.html"><i>syslog</i>()</a><br>
|
|
<a href="../functions/tmpfile.html"><i>tmpfile</i>()</a><br>
|
|
<a href="../functions/tmpnam.html"><i>tmpnam</i>()</a><br>
|
|
<a href="../functions/ttyname.html"><i>ttyname</i>()</a><br>
|
|
<a href="../functions/ttyname_r.html"><i>ttyname_r</i>()</a><br>
|
|
<a href="../functions/ungetc.html"><i>ungetc</i>()</a><br>
|
|
<a href="../functions/ungetwc.html"><i>ungetwc</i>()</a><br>
|
|
<a href="../functions/unlink.html"><i>unlink</i>()</a><br>
|
|
<a href="../functions/vfprintf.html"><i>vfprintf</i>()</a><br>
|
|
<a href="../functions/vfwprintf.html"><i>vfwprintf</i>()</a><br>
|
|
<a href="../functions/vprintf.html"><i>vprintf</i>()</a><br>
|
|
<a href="../functions/vwprintf.html"><i>vwprintf</i>()</a><br>
|
|
<a href="../functions/wprintf.html"><i>wprintf</i>()</a><br>
|
|
<a href="../functions/wscanf.html"><i>wscanf</i>()</a><br>
|
|
</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>An implementation shall not introduce cancelation points into any other functions specified in this volume of
|
|
IEEE Std 1003.1-2001.</p>
|
|
|
|
<p>The side effects of acting upon a cancelation request while suspended during a call of a function are the same as the side
|
|
effects that may be seen in a single-threaded program when a call to a function is interrupted by a signal and the given function
|
|
returns [EINTR]. Any such side effects occur before any cancelation cleanup handlers are called.</p>
|
|
|
|
<p>Whenever a thread has cancelability enabled and a cancelation request has been made with that thread as the target, and the
|
|
thread then calls any function that is a cancelation point (such as <a href=
|
|
"../functions/pthread_testcancel.html"><i>pthread_testcancel</i>()</a> or <a href="../functions/read.html"><i>read</i>()</a>), the
|
|
cancelation request shall be acted upon before the function returns. If a thread has cancelability enabled and a cancelation
|
|
request is made with the thread as a target while the thread is suspended at a cancelation point, the thread shall be awakened and
|
|
the cancelation request shall be acted upon. However, if the thread is suspended at a cancelation point and the event for which it
|
|
is waiting occurs before the cancelation request is acted upon, it is unspecified whether the cancelation request is acted upon or
|
|
whether the cancelation request remains pending and the thread resumes normal execution.</p>
|
|
|
|
<h5><a name="tag_02_09_05_03"></a>Thread Cancelation Cleanup Handlers</h5>
|
|
|
|
<p>Each thread maintains a list of cancelation cleanup handlers. The programmer uses the <a href=
|
|
"../functions/pthread_cleanup_push.html"><i>pthread_cleanup_push</i>()</a> and <a href=
|
|
"../functions/pthread_cleanup_pop.html"><i>pthread_cleanup_pop</i>()</a> functions to place routines on and remove routines from
|
|
this list.</p>
|
|
|
|
<p>When a cancelation request is acted upon, the routines in the list are invoked one by one in LIFO sequence; that is, the last
|
|
routine pushed onto the list (Last In) is the first to be invoked (First Out). The thread invokes the cancelation cleanup handler
|
|
with cancelation disabled until the last cancelation cleanup handler returns. When the cancelation cleanup handler for a scope is
|
|
invoked, the storage for that scope remains valid. If the last cancelation cleanup handler returns, thread execution is terminated
|
|
and a status of PTHREAD_CANCELED is made available to any threads joining with the target. The symbolic constant PTHREAD_CANCELED
|
|
expands to a constant expression of type ( <b>void *</b>) whose value matches no pointer to an object in memory nor the value
|
|
NULL.</p>
|
|
|
|
<p>The cancelation cleanup handlers are also invoked when the thread calls <a href=
|
|
"../functions/pthread_exit.html"><i>pthread_exit</i>()</a>.</p>
|
|
|
|
<p>A side effect of acting upon a cancelation request while in a condition variable wait is that the mutex is re-acquired before
|
|
calling the first cancelation cleanup handler. In addition, the thread is no longer considered to be waiting for the condition and
|
|
the thread shall not have consumed any pending condition signals on the condition.</p>
|
|
|
|
<p>A cancelation cleanup handler cannot exit via <a href="../functions/longjmp.html"><i>longjmp</i>()</a> or <a href=
|
|
"../functions/siglongjmp.html"><i>siglongjmp</i>()</a>.</p>
|
|
|
|
<h5><a name="tag_02_09_05_04"></a>Async-Cancel Safety</h5>
|
|
|
|
<p>The <a href="../functions/pthread_cancel.html"><i>pthread_cancel</i>()</a>, <a href=
|
|
"../functions/pthread_setcancelstate.html"><i>pthread_setcancelstate</i>()</a>, and <a href=
|
|
"../functions/pthread_setcanceltype.html"><i>pthread_setcanceltype</i>()</a> functions are defined to be async-cancel safe.</p>
|
|
|
|
<p>No other functions in this volume of IEEE Std 1003.1-2001 are required to be async-cancel-safe.</p>
|
|
|
|
<h4><a name="tag_02_09_06"></a>Thread Read-Write Locks</h4>
|
|
|
|
<p>Multiple readers, single writer (read-write) locks allow many threads to have simultaneous read-only access to data while
|
|
allowing only one thread to have exclusive write access at any given time. They are typically used to protect data that is read
|
|
more frequently than it is changed.</p>
|
|
|
|
<p>One or more readers acquire read access to the resource by performing a read lock operation on the associated read-write lock. A
|
|
writer acquires exclusive write access by performing a write lock operation. Basically, all readers exclude any writers and a
|
|
writer excludes all readers and any other writers.</p>
|
|
|
|
<p>A thread that has blocked on a read-write lock (for example, has not yet returned from a <a href=
|
|
"../functions/pthread_rwlock_rdlock.html"><i>pthread_rwlock_rdlock</i>()</a> or <a href=
|
|
"../functions/pthread_rwlock_wrlock.html"><i>pthread_rwlock_wrlock</i>()</a> call) shall not prevent any unblocked thread that is
|
|
eligible to use the same processing resources from eventually making forward progress in its execution. Eligibility for processing
|
|
resources shall be determined by the scheduling policy.</p>
|
|
|
|
<p>Read-write locks can be used to synchronize threads in the current process and other processes if they are allocated in memory
|
|
that is writable and shared among the cooperating processes and have been initialized for this behavior.</p>
|
|
|
|
<h4><a name="tag_02_09_07"></a>Thread Interactions with Regular File Operations</h4>
|
|
|
|
<p>All of the functions <a href="../functions/chmod.html"><i>chmod</i>()</a>, <a href="../functions/close.html"><i>close</i>()</a>,
|
|
<a href="../functions/fchmod.html"><i>fchmod</i>()</a>, <a href="../functions/fcntl.html"><i>fcntl</i>()</a>, <a href=
|
|
"../functions/fstat.html"><i>fstat</i>()</a>, <a href="../functions/ftruncate.html"><i>ftruncate</i>()</a>, <a href=
|
|
"../functions/lseek.html"><i>lseek</i>()</a>, <a href="../functions/open.html"><i>open</i>()</a>, <a href=
|
|
"../functions/read.html"><i>read</i>()</a>, <a href="../functions/readlink.html"><i>readlink</i>()</a>, <a href=
|
|
"../functions/stat.html"><i>stat</i>()</a>, <a href="../functions/symlink.html"><i>symlink</i>()</a>, and <a href=
|
|
"../functions/write.html"><i>write</i>()</a> shall be atomic with respect to each other in the effects specified in
|
|
IEEE Std 1003.1-2001 when they operate on regular files. If two threads each call one of these functions, each call shall
|
|
either see all of the specified effects of the other call, or none of them.</p>
|
|
|
|
<hr>
|
|
<h4><a name="tag_02_09_08"></a>Footnotes</h4>
|
|
|
|
<dl compact>
|
|
<dt><a name="tag_foot_1">1.</a></dt>
|
|
|
|
<dd>The functions in the table are not shaded to denote applicable options. Individual reference pages should be consulted.</dd>
|
|
|
|
<dt><a name="tag_foot_2">2.</a></dt>
|
|
|
|
<dd>When the <i>cmd</i> argument is F_SETLKW.</dd>
|
|
|
|
<dt><a name="tag_foot_3">3.</a></dt>
|
|
|
|
<dd>For any value of the <i>cmd</i> argument.</dd>
|
|
</dl>
|
|
|
|
<hr size="2" noshade>
|
|
<center><font size="2">UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
</font> [ <a href="../mindex.html">Main Index</a>]</center>
|
|
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|