📄 threads.html
字号:
or<i>disabled</i>cancelability states.<h5><a name = "tag_000_010_008_001"> </a>Cancelability States</h5><p>The cancelability state of a thread determines the action takenupon receipt of a cancellation request.The thread may control cancellation in a number of ways.<p>Each thread maintains its own cancelability state,which may be encoded in two bits:<dl compact><dt><i>Cancelability Enable</i><dd>When cancelability is PTHREAD_CANCEL_DISABLE,cancellation requests against the target thread are held pending.By default, cancelability is set to PTHREAD_CANCEL_ENABLE.<dt><i>Cancelability Type</i><dd>When cancelability is enabled and the cancelability type isPTHREAD_CANCEL_ASYNCHRONOUS,new or pending cancellation requests may be acted upon at any time.When cancelability is enabled and the cancelability type isPTHREAD_CANCEL_DEFERRED,cancellation requests are held pending until a cancellation point(see below) is reached.If cancelability is disabled,the setting of the cancelabilitytype has no immediate effect as all cancellation requests are held pending,however, once cancelability is enabled again the new type will be in effect.The cancelability type is PTHREAD_CANCEL_DEFERREDin all newly created threads including the thread in which<i>main()</i>was first invoked.</dl><h5><a name = "tag_000_010_008_002"> </a>Cancellation Points</h5><p>Cancellation points occurwhen a thread is executing the following functions:<pre><i><a href="aio_suspend.html">aio_suspend()</a></i><i><a href="close.html">close()</a></i><i><a href="creat.html">creat()</a></i><i><a href="fcntl.html">fcntl()</a></i><i><a href="fsync.html">fsync()</a></i><i><a href="getmsg.html">getmsg()</a></i><i><a href="getpmsg.html">getpmsg()</a></i><i><a href="lockf.html">lockf()</a></i><i><a href="mq_receive.html">mq_receive()</a></i><i><a href="mq_send.html">mq_send()</a></i><i><a href="msgrcv.html">msgrcv()</a></i><i><a href="msgsnd.html">msgsnd()</a></i><i><a href="msync.html">msync()</a></i><i><a href="nanosleep.html">nanosleep()</a></i><i><a href="open.html">open()</a></i><i><a href="pause.html">pause()</a></i><i><a href="poll.html">poll()</a></i><i><a href="pread.html">pread()</a></i><i><a href="pthread_cond_timedwait.html">pthread_cond_timedwait()</a></i><i><a href="pthread_cond_wait.html">pthread_cond_wait()</a></i><i><a href="pthread_join.html">pthread_join()</a></i><i><a href="pthread_testcancel.html">pthread_testcancel()</a></i><i><a href="putmsg.html">putmsg()</a></i><i><a href="putpmsg.html">putpmsg()</a></i><i><a href="pwrite.html">pwrite()</a></i><i><a href="read.html">read()</a></i><i><a href="readv.html">readv()</a></i><i><a href="select.html">select()</a></i><i><a href="sem_wait.html">sem_wait()</a></i><i><a href="sigpause.html">sigpause()</a></i><i><a href="sigsuspend.html">sigsuspend()</a></i><i><a href="sigtimedwait.html">sigtimedwait()</a></i><i><a href="sigwait.html">sigwait()</a></i><i><a href="sigwaitinfo.html">sigwaitinfo()</a></i><i><a href="sleep.html">sleep()</a></i><i><a href="system.html">system()</a></i><i><a href="tcdrain.html">tcdrain()</a></i><i><a href="usleep.html">usleep()</a></i><i><a href="wait.html">wait()</a></i><i><a href="wait3.html">wait3()</a></i><i><a href="waitid.html">waitid()</a></i><i><a href="waitpid.html">waitpid()</a></i><i><a href="write.html">write()</a></i><i><a href="writev.html">writev()</a></i></pre><p><p>A cancellation point may also occurwhen a thread is executing the following functions:<p><pre><i><a href="catclose.html">catclose()</a></i><i><a href="catgets.html">catgets()</a></i><i><a href="catopen.html">catopen()</a></i><i><a href="closedir.html">closedir()</a></i><i><a href="closelog.html">closelog()</a></i><i><a href="ctermid.html">ctermid()</a></i><i><a href="dbm_close.html">dbm_close()</a></i><i><a href="dbm_delete.html">dbm_delete()</a></i><i><a href="dbm_fetch.html">dbm_fetch()</a></i><i><a href="dbm_nextkey.html">dbm_nextkey()</a></i><i><a href="dbm_open.html">dbm_open()</a></i><i><a href="dbm_store.html">dbm_store()</a></i><i><a href="dlclose.html">dlclose()</a></i><i><a href="dlopen.html">dlopen()</a></i><i><a href="endgrent.html">endgrent()</a></i><i><a href="endpwent.html">endpwent()</a></i><i><a href="endutxent.html">endutxent()</a></i><i><a href="fclose.html">fclose()</a></i><i><a href="fcntl.html">fcntl()</a></i><i><a href="fflush.html">fflush()</a></i><i><a href="fgetc.html">fgetc()</a></i><i><a href="fgetpos.html">fgetpos()</a></i><i><a href="fgets.html">fgets()</a></i><i><a href="fgetwc.html">fgetwc()</a></i><i><a href="fgetws.html">fgetws()</a></i><i><a href="fopen.html">fopen()</a></i><i><a href="fprintf.html">fprintf()</a></i><i><a href="fputc.html">fputc()</a></i><i><a href="fputs.html">fputs()</a></i><i><a href="fputwc.html">fputwc()</a></i><i><a href="fputws.html">fputws()</a></i><i><a href="fread.html">fread()</a></i><i><a href="freopen.html">freopen()</a></i><i><a href="fscanf.html">fscanf()</a></i><i><a href="fseek.html">fseek()</a></i><i><a href="fseeko.html">fseeko()</a></i><i><a href="fsetpos.html">fsetpos()</a></i><i><a href="ftell.html">ftell()</a></i><i><a href="ftello.html">ftello()</a></i><i><a href="ftw.html">ftw()</a></i><i><a href="fwprintf.html">fwprintf()</a></i><i><a href="fwrite.html">fwrite()</a></i><i><a href="fwscanf.html">fwscanf()</a></i><i><a href="getc.html">getc()</a></i><i><a href="getc_unlocked.html">getc_unlocked()</a></i><i><a href="getchar.html">getchar()</a></i><i><a href="getchar_unlocked.html">getchar_unlocked()</a></i><i><a href="getcwd.html">getcwd()</a></i><i><a href="getdate.html">getdate()</a></i><i><a href="getgrent.html">getgrent()</a></i><i><a href="getgrgid.html">getgrgid()</a></i><i><a href="getgrgid.html">getgrgid_r()</a></i><i><a href="getgrnam.html">getgrnam()</a></i><i><a href="getgrnam.html">getgrnam_r()</a></i><i><a href="getlogin.html">getlogin()</a></i><i><a href="getlogin.html">getlogin_r()</a></i><i><a href="getpwent.html">getpwent()</a></i><i><a href="getpwnam.html">getpwnam()</a></i><i><a href="getpwnam.html">getpwnam_r()</a></i><i><a href="getpwuid.html">getpwuid()</a></i><i><a href="getpwuid.html">getpwuid_r()</a></i><i><a href="gets.html">gets()</a></i><i><a href="getutxent.html">getutxent()</a></i><i><a href="getutxid.html">getutxid()</a></i><i><a href="getutxline.html">getutxline()</a></i><i><a href="getw.html">getw()</a></i><i><a href="getwc.html">getwc()</a></i><i><a href="getwchar.html">getwchar()</a></i><i><a href="getwd.html">getwd()</a></i><i><a href="glob.html">glob()</a></i><i><a href="iconv_close.html">iconv_close()</a></i><i><a href="iconv_open.html">iconv_open()</a></i><i><a href="ioctl.html">ioctl()</a></i><i><a href="lseek.html">lseek()</a></i><i><a href="mkstemp.html">mkstemp()</a></i><i><a href="nftw.html">nftw()</a></i><i><a href="opendir.html">opendir()</a></i><i><a href="openlog.html">openlog()</a></i><i><a href="pclose.html">pclose()</a></i><i><a href="perror.html">perror()</a></i><i><a href="popen.html">popen()</a></i><i><a href="printf.html">printf()</a></i><i><a href="putc.html">putc()</a></i><i><a href="putc_unlocked.html">putc_unlocked()</a></i><i><a href="putchar.html">putchar()</a></i><i><a href="putchar_unlocked.html">putchar_unlocked()</a></i><i><a href="puts.html">puts()</a></i><i><a href="pututxline.html">pututxline()</a></i><i><a href="putw.html">putw()</a></i><i><a href="putwc.html">putwc()</a></i><i><a href="putwchar.html">putwchar()</a></i><i><a href="readdir.html">readdir()</a></i><i><a href="readdir.html">readdir_r()</a></i><i><a href="remove.html">remove()</a></i><i><a href="rename.html">rename()</a></i><i><a href="rewind.html">rewind()</a></i><i><a href="rewinddir.html">rewinddir()</a></i><i><a href="scanf.html">scanf()</a></i><i><a href="seekdir.html">seekdir()</a></i><i><a href="semop.html">semop()</a></i><i><a href="setgrent.html">setgrent()</a></i><i><a href="setpwent.html">setpwent()</a></i><i><a href="setutxent.html">setutxent()</a></i><i><a href="strerror.html">strerror()</a></i><i><a href="syslog.html">syslog()</a></i><i><a href="tmpfile.html">tmpfile()</a></i><i><a href="tmpnam.html">tmpnam()</a></i><i><a href="ttyname.html">ttyname()</a></i><i><a href="ttyname.html">ttyname_r()</a></i><i><a href="ungetc.html">ungetc()</a></i><i><a href="ungetwc.html">ungetwc()</a></i><i><a href="unlink.html">unlink()</a></i><i><a href="vfprintf.html">vfprintf()</a></i><i><a href="vfwprintf.html">vfwprintf()</a></i><i><a href="vprintf.html">vprintf()</a></i><i><a href="vwprintf.html">vwprintf()</a></i><i><a href="wprintf.html">wprintf()</a></i><i><a href="wscanf.html">wscanf()</a></i></pre><p>Note, that for<i><a href="fcntl.html">fcntl()</a></i>,for any value of the<i>cmd</i>argument.<p>An implementation will not introduce cancellation pointsinto any other functions specified in this specification.<p>The side effects of acting upon a cancellation requestwhile suspended during a call of a functionis the same as the side effectsthat may be seen in a single-threaded programwhen a call to a function is interrupted by a signaland the given function returns [EINTR].Any such side effects occur before anycancellation cleanup handlers are called.<p>Whenever a thread has cancelability enabledand a cancellation request has been made with that thread as the targetand the thread calls<i><a href="pthread_testcancel.html">pthread_testcancel()</a></i>,then the cancellation request is acted upon before<i><a href="pthread_testcancel.html">pthread_testcancel()</a></i>returns.If a thread has cancelability enabledand the thread has an asynchronous cancellation request pending andthe thread is suspended at a cancellation point waiting for an event to occur,then the cancellation request will be acted upon.However, if the thread is suspended at a cancellation pointand the event that it is waiting for occursbefore the cancellation request is acted upon, it isunspecified whether the cancellation request is acted uponor whether the request remains pending and the thread resumes normal execution.<h5><a name = "tag_000_010_008_003"> </a>Thread Cancellation Cleanup Handlers</h5><p>Each thread maintains a list of cancellation cleanup handlers.The programmer uses the functions<i><a href="pthread_cleanup_push.html">pthread_cleanup_push()</a></i>and<i><a href="pthread_cleanup_pop.html">pthread_cleanup_pop()</a></i>to place routines on and remove routines from this list.<p>When a cancellation request is acted upon,the routines in the list are invoked one by one in LIFOsequence; that is, the last routine pushed onto the list (Last In)is the first to be invoked (First Out).The thread invokes the cancellation cleanup handlerwith cancellation disabled until the lastcancellation cleanup handler returns.When the cancellation cleanup handlerfor a scope is invoked,the storage for that scope remains valid.If the last cancellation cleanup handlerreturns, thread execution is terminatedand a status of PTHREAD_CANCELEDis made available to any threads joining with the target.The symbolic constant PTHREAD_CANCELEDexpands to a constant expression of type (<b> void *</b>)whose value matches no pointer to an object in memory nor the value NULL.<p>The cancellation cleanup handlersare also invoked when the thread calls<i><a href="pthread_exit.html">pthread_exit()</a></i>.<p>A side effect of acting upon a cancellation requestwhile in a condition variable wait is thatthe mutex is reacquired before calling the firstcancellation cleanup handler.In addition,the thread is no longer considered to be waiting for the conditionand the thread will not have consumed any pendingcondition signalson the condition.<p>A cancellation cleanup handler cannot exit via<i><a href="longjmp.html">longjmp()</a></i>or<i><a href="siglongjmp.html">siglongjmp()</a></i>.<h5><a name = "tag_000_010_008_004"> </a>Async-Cancel Safety</h5>The<i><a href="pthread_cancel.html">pthread_cancel()</a></i>,<i><a href="pthread_setcancelstate.html">pthread_setcancelstate()</a></i>and<i><a href="pthread_setcanceltype.html">pthread_setcanceltype()</a></i>functions are defined to be async-cancel safe.<p>No other functions in this specificationare required to be async-cancel safe.<h4><a name = "tag_000_010_009"> </a>Thread Read-Write Locks</h4><p>Multiple readers, single writer (read-write) locks allow manythreads to have simultaneous read-only access to datawhile allowing only one thread to have write access at any giventime. They are typically used to protect data that is read-onlymore frequently than it is changed.<p>Read-write locks can be used to synchronise threads in the currentprocess and other processes if they are allocated in memory thatis writable and shared among the cooperating processes and have beeninitialised for this behaviour.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -