📄 xsh_chap02_09.html
字号:
<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/stat.html"><i>stat</i>()</a><br><a href="../functions/strerror.html"><i>strerror</i>()</a><br><a href="../functions/strerror_r.html"><i>strerror_r</i>()</a><br><a href="../functions/strftime.html"><i>strftime</i>()</a><br><a href="../functions/symlink.html"><i>symlink</i>()</a><br><a href="../functions/sync.html"><i>sync</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/tzset.html"><i>tzset</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/wcsftime.html"><i>wcsftime</i>()</a><br><a href="../functions/wordexp.html"><i>wordexp</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 cancellation points into any other functions specified in this volume ofIEEE Std 1003.1-2001.</p><p>The side effects of acting upon a cancellation request while suspended during a call of a function are the same as the sideeffects that may be seen in a single-threaded program when a call to a function is interrupted by a signal and the given functionreturns [EINTR]. Any such side effects occur before any cancellation cleanup handlers are called.</p><p>Whenever a thread has cancelability enabled and a cancellation request has been made with that thread as the target, and thethread then calls any function that is a cancellation point (such as <a href="../functions/pthread_testcancel.html"><i>pthread_testcancel</i>()</a> or <a href="../functions/read.html"><i>read</i>()</a>), thecancellation request shall be acted upon before the function returns. If a thread has cancelability enabled and a cancellationrequest is made with the thread as a target while the thread is suspended at a cancellation point, the thread shall be awakened andthe cancellation request shall be acted upon. However, if the thread is suspended at a cancellation point and the event for whichit is waiting occurs before the cancellation request is acted upon, it is unspecified whether the cancellation request is actedupon or whether the cancellation request remains pending and the thread resumes normal execution.</p><h5><a name="tag_02_09_05_03"></a>Thread Cancellation Cleanup Handlers</h5><p>Each thread maintains a list of cancellation 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 fromthis list.</p><p>When a cancellation request is acted upon, or when a thread calls <a href="../functions/pthread_exit.html"><i>pthread_exit</i>()</a>, the thread first disables cancellation by setting its cancelabilitystate to PTHREAD_CANCEL_DISABLE and its cancelability type to PTHREAD_CANCEL_DEFERRED. The cancelability state shall remain set toPTHREAD_CANCEL_DISABLE until the thread has terminated. The behavior is undefined if a cancellation cleanup handler orthread-specific data destructor routine changes the cancelability state to PTHREAD_CANCEL_ENABLE.</p><p>The routines in the thread's list of cancellation cleanup handlers are invoked one by one in LIFO sequence; that is, the lastroutine pushed onto the list (Last In) is the first to be invoked (First Out). When the cancellation cleanup handler for a scope isinvoked, the storage for that scope remains valid. If the last cancellation cleanup handler returns, thread-specific datadestructors (if any) associated with thread-specific data keys for which the thread has non-NULL values will be run, in unspecifiedorder, as described for <a href="../functions/pthread_key_create.html"><i>pthread_key_create</i>()</a>.</p><p>After all cancellation cleanup handlers and thread-specific data destructors have returned, thread execution is terminated. Ifthe thread has terminated because of a call to <a href="../functions/pthread_exit.html"><i>pthread_exit</i>()</a>, the<i>value_ptr</i> argument is made available to any threads joining with the target. If the thread has terminated by acting on acancellation request, a status of PTHREAD_CANCELED is made available to any threads joining with the target. The symbolic constantPTHREAD_CANCELED expands to a constant expression of type ( <b>void *</b>) whose value matches no pointer to an object in memorynor the value NULL.</p><p>A side effect of acting upon a cancellation request while in a condition variable wait is that the mutex is re-acquired beforecalling the first cancellation cleanup handler. In addition, the thread is no longer considered to be waiting for the condition andthe thread shall not have consumed any pending condition signals on the condition.</p><p>A cancellation 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"> 2.9.6 </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 whileallowing only one thread to have exclusive write access at any given time. They are typically used to protect data that is readmore 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. Awriter acquires exclusive write access by performing a write lock operation. Basically, all readers exclude any writers and awriter 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 iseligible to use the same processing resources from eventually making forward progress in its execution. Eligibility for processingresources 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 memorythat is writable and shared among the cooperating processes and have been initialized for this behavior.</p><h4><a name="tag_02_09_07"> 2.9.7 </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 inIEEE Std 1003.1-2001 when they operate on regular files. If two threads each call one of these functions, each call shalleither see all of the specified effects of the other call, or none of them.</p><h4><a name="tag_02_09_08"> 2.9.8 </a>Use of Application-Managed Thread Stacks</h4><p>An ``application-managed thread stack'' is a region of memory allocated by the application-for example, memory returned by the<a href="../functions/malloc.html"><i>malloc</i>()</a> or <a href="../functions/mmap.html"><i>mmap</i>()</a> functions-anddesignated as a stack through the act of passing an address related to that memory as the <i>stackaddr</i> argument to <a href="../functions/pthread_attr_setstackaddr.html"><i>pthread_attr_setstackaddr</i>()</a> (obsolete) or by passing the address and sizeof the stack, respectively, as the <i>stackaddr</i> and <i>stacksize</i> arguments to <a href="../functions/pthread_attr_setstack.html"><i>pthread_attr_setstack</i>()</a>. Application-managed stacks allow the application toprecisely control the placement and size of a stack.</p><p>The application grants to the implementation permanent ownership of and control over the application-managed stack when theattributes object in which the <i>stack</i> or <i>stackaddr</i> attribute has been set is used, either by presenting thatattribute's object as the <i>attr</i> argument in a call to <a href="../functions/pthread_create.html"><i>pthread_create</i>()</a>that completes successfully, or by storing a pointer to the attributes object in the <i>sigev_notify_attributes</i> member of a<b>struct sigevent</b> and passing that <b>struct sigevent</b> to a function accepting such argument that completes successfully.The application may thereafter utilize the memory within the stack only within the normal context of stack usage within or properlysynchronized with a thread that has been scheduled by the implementation with stack pointer value(s) that are within the range ofthat stack. In particular, the region of memory cannot be freed, nor can it be later specified as the stack for another thread.</p><p>When specifying an attributes object with an application-managed stack through the <i>sigev_notify_attributes</i> member of a<b>struct sigevent</b>, the results are undefined if the requested signal is generated multiple times (as for a repeatingtimer).</p><p>Until an attributes object in which the <i>stack</i> or <i>stackaddr</i> attribute has been set is used, the application retainsownership of and control over the memory allocated to the stack. It may free or reuse the memory as long as it either deletes theattributes object, or before using the attributes object replaces the stack by making an additional call to the same function,either <a href="../functions/pthread_attr_setstackaddr.html"><i>pthread_attr_setstackaddr</i>()</a> or <a href="../functions/pthread_attr_setstack.html"><i>pthread_attr_setstack</i>()</a>, that was used originally to designate the stack.There is no mechanism to retract the reference to an application-managed stack by an existing attributes object.</p><p>Once an attributes object with an application-managed stack has been used, that attributes object cannot be used again by asubsequent call to <a href="../functions/pthread_create.html"><i>pthread_create</i>()</a> or any function accepting a <b>structsigevent</b> with <i>sigev_notify_attributes</i> containing a pointer to the attributes object, without designating an unusedapplication-managed stack by making an additional call to the function originally used to define the stack, <a href="../functions/pthread_attr_setstack.html"><i>pthread_attr_setstack</i>()</a> or <a href="../functions/pthread_attr_setstackaddr.html"><i>pthread_attr_setstackaddr</i>()</a>.</p><hr><h4><a name="tag_02_09_09"></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_4">4.</a></dt><dd>For any value of the <i>cmd</i> argument.</dd><dt><a name="tag_foot_4">4.</a></dt><dd>If <i>opterr</i> is non-zero.</dd></dl><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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -