⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threads.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>Threads</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><blockquote><center><h3><a name = "tag_000_010">&nbsp;</a>Threads</h3></center><xref type="2" name="threads"></xref>This defines interfaces and functionality to support multiple flowsof control, called<i>threads</i>,within a process.<p>Threads define system interfacesto support the source portability of applications.The key elements defining the scope are:<ol type = a><p><li>defining a sufficient set of functionalityto support multiple threads of control within a process<p><li>defining a sufficient set of functionality to support therealtime application domain<p><li>defining sufficient performance constraints and performancerelated functions to allow a realtime applicationto achieve deterministic response from the system.<p></ol><p>The definition of realtime used in defining the scope of thisspecification is:<pre><dl compact><dt> <dd>The ability of the system to provide a required level of servicein a bounded response time.</dl></pre><p><p>Wherever possible, the requirements of other application environmentsare included in the interface definition.The Threads interfaces are specifically targetedat supporting tightly coupled multitasking environmentsincluding multiprocessors and advanced language constructs.<p>The specific functional areas covered by Threadsand their scope includes:<ul><p><li>Thread management: the creation, control, and terminationof multiple flows of control in the same processunder the assumption of a common shared address space.<p><li>Synchronisation primitives optimisedfor tightly coupled operation of multiple control flowsin a common, shared address space.<p><li>Harmonization of the threads interfaces with the existing BASEinterfaces.<p></ul><h4><a name = "tag_000_010_001">&nbsp;</a>Supported Interfaces</h4><p>On XSI-conformant systems,_POSIX_THREADS,_POSIX_THREAD_ATTR_STACKADDR,_POSIX_THREAD_ATTR_STACKSIZEand_POSIX_THREAD_PROCESS_SHAREDare always defined.Therefore, the following threads interfaces are always supported:<h5><a name = "tag_000_010_001_001">&nbsp;</a>POSIX Interfaces</h5><p><pre><i><a href="pthread_atfork.html">pthread_atfork()</a></i><i><a href="pthread_attr_destroy.html">pthread_attr_destroy()</a></i><i><a href="pthread_attr_getdetachstate.html">pthread_attr_getdetachstate()</a></i><i><a href="pthread_attr_getschedparam.html">pthread_attr_getschedparam()</a></i><i><a href="pthread_attr_getstackaddr.html">pthread_attr_getstackaddr()</a></i><i><a href="pthread_attr_getstacksize.html">pthread_attr_getstacksize()</a></i><i><a href="pthread_attr_init.html">pthread_attr_init()</a></i><i><a href="pthread_attr_setdetachstate.html">pthread_attr_setdetachstate()</a></i><i><a href="pthread_attr_setschedparam.html">pthread_attr_setschedparam()</a></i><i><a href="pthread_attr_setstackaddr.html">pthread_attr_setstackaddr()</a></i><i><a href="pthread_attr_setstacksize.html">pthread_attr_setstacksize()</a></i><i><a href="pthread_cancel.html">pthread_cancel()</a></i><i><a href="pthread_cleanup_pop.html">pthread_cleanup_pop()</a></i><i><a href="pthread_cleanup_push.html">pthread_cleanup_push()</a></i><i><a href="pthread_cond_broadcast.html">pthread_cond_broadcast()</a></i><i><a href="pthread_cond_destroy.html">pthread_cond_destroy()</a></i><i><a href="pthread_cond_init.html">pthread_cond_init()</a></i><i><a href="pthread_cond_signal.html">pthread_cond_signal()</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_condattr_destroy.html">pthread_condattr_destroy()</a></i><i><a href="pthread_condattr_getpshared.html">pthread_condattr_getpshared()</a></i><i><a href="pthread_condattr_init.html">pthread_condattr_init()</a></i><i><a href="pthread_condattr_setpshared.html">pthread_condattr_setpshared()</a></i><i><a href="pthread_create.html">pthread_create()</a></i><i><a href="pthread_detach.html">pthread_detach()</a></i><i><a href="pthread_equal.html">pthread_equal()</a></i><i><a href="pthread_exit.html">pthread_exit()</a></i><i><a href="pthread_getspecific.html">pthread_getspecific()</a></i><i><a href="pthread_join.html">pthread_join()</a></i><i><a href="pthread_key_create.html">pthread_key_create()</a></i><i><a href="pthread_key_delete.html">pthread_key_delete()</a></i><i><a href="pthread_kill.html">pthread_kill()</a></i><i><a href="pthread_mutex_destroy.html">pthread_mutex_destroy()</a></i><i><a href="pthread_mutex_init.html">pthread_mutex_init()</a></i><i><a href="pthread_mutex_lock.html">pthread_mutex_lock()</a></i><i><a href="pthread_mutex_trylock.html">pthread_mutex_trylock()</a></i><i><a href="pthread_mutex_unlock.html">pthread_mutex_unlock()</a></i><i><a href="pthread_mutexattr_destroy.html">pthread_mutexattr_destroy()</a></i><i><a href="pthread_mutexattr_getpshared.html">pthread_mutexattr_getpshared()</a></i><i><a href="pthread_mutexattr_init.html">pthread_mutexattr_init()</a></i><i><a href="pthread_mutexattr_setpshared.html">pthread_mutexattr_setpshared()</a></i><i><a href="pthread_once.html">pthread_once()</a></i><i><a href="pthread_self.html">pthread_self()</a></i><i><a href="pthread_setcancelstate.html">pthread_setcancelstate()</a></i><i><a href="pthread_setcanceltype.html">pthread_setcanceltype()</a></i><i><a href="pthread_setspecific.html">pthread_setspecific()</a></i><i><a href="pthread_sigmask.html">pthread_sigmask()</a></i><i><a href="pthread_testcancel.html">pthread_testcancel()</a></i><i><a href="sigwait.html">sigwait()</a></i></pre><h5><a name = "tag_000_010_001_002">&nbsp;</a>X/Open Interfaces</h5><pre><i><a href="pthread_attr_getguardsize.html">pthread_attr_getguardsize()</a></i><i><a href="pthread_attr_setguardsize.html">pthread_attr_setguardsize()</a></i><i><a href="pthread_getconcurrency.html">pthread_getconcurrency()</a></i><i><a href="pthread_mutexattr_gettype.html">pthread_mutexattr_gettype()</a></i><i><a href="pthread_mutexattr_settype.html">pthread_mutexattr_settype()</a></i><i><a href="pthread_rwlock_destroy.html">pthread_rwlock_destroy()</a></i><i><a href="pthread_rwlock_init.html">pthread_rwlock_init()</a></i><i><a href="pthread_rwlock_rdlock.html">pthread_rwlock_rdlock()</a></i><i><a href="pthread_rwlock_tryrdlock.html">pthread_rwlock_tryrdlock()</a></i><i><a href="pthread_rwlock_trywrlock.html">pthread_rwlock_trywrlock()</a></i><i><a href="pthread_rwlock_unlock.html">pthread_rwlock_unlock()</a></i><i><a href="pthread_rwlock_wrlock.html">pthread_rwlock_wrlock()</a></i><i><a href="pthread_rwlockattr_destroy.html">pthread_rwlockattr_destroy()</a></i><i><a href="pthread_rwlockattr_getpshared.html">pthread_rwlockattr_getpshared()</a></i><i><a href="pthread_rwlockattr_init.html">pthread_rwlockattr_init()</a></i><i><a href="pthread_rwlockattr_setpshared.html">pthread_rwlockattr_setpshared()</a></i><i><a href="pthread_setconcurrency.html">pthread_setconcurrency()</a></i></pre><p>On XSI-conformant systems, _POSIX_THREAD_SAFE_FUNCTIONS is alwaysdefined.Therefore, the following interfaces are always supported:<p><pre><i><a href="asctime.html">asctime_r()</a></i><i><a href="ctime.html">ctime_r()</a></i><i><a href="flockfile.html">flockfile()</a></i><i><a href="ftrylockfile.html">ftrylockfile()</a></i><i><a href="funlockfile.html">funlockfile()</a></i><i><a href="getc_unlocked.html">getc_unlocked()</a></i><i><a href="getchar_unlocked.html">getchar_unlocked()</a></i><i><a href="getgrgid.html">getgrgid_r()</a></i><i><a href="getgrnam.html">getgrnam_r()</a></i><i><a href="getpwnam.html">getpwnam_r()</a></i><i><a href="getpwuid.html">getpwuid_r()</a></i><i><a href="gmtime.html">gmtime_r()</a></i><i><a href="localtime.html">localtime_r()</a></i><i><a href="putc_unlocked.html">putc_unlocked()</a></i><i><a href="putchar_unlocked.html">putchar_unlocked()</a></i><i><a href="rand.html">rand_r()</a></i><i><a href="readdir.html">readdir_r()</a></i><i><a href="strtok.html">strtok_r()</a></i></pre><p>The following threads interfaces are only supported on XSI-conformantsystems if the Realtime Threads Feature Group is supported (see<xref href=realtime_threads><a href="feature.html#tag_000_005_003">Realtime Threads</a></xref>):<p><pre><i><a href="pthread_attr_getinheritsched.html">pthread_attr_getinheritsched()</a></i><i><a href="pthread_attr_getschedpolicy.html">pthread_attr_getschedpolicy()</a></i><i><a href="pthread_attr_getscope.html">pthread_attr_getscope()</a></i><i><a href="pthread_attr_setinheritsched.html">pthread_attr_setinheritsched()</a></i><i><a href="pthread_attr_setschedpolicy.html">pthread_attr_setschedpolicy()</a></i><i><a href="pthread_attr_setscope.html">pthread_attr_setscope()</a></i><i><a href="pthread_getschedparam.html">pthread_getschedparam()</a></i><i><a href="pthread_mutex_getprioceiling.html">pthread_mutex_getprioceiling()</a></i><i><a href="pthread_mutex_setprioceiling.html">pthread_mutex_setprioceiling()</a></i><i><a href="pthread_mutexattr_getprioceiling.html">pthread_mutexattr_getprioceiling()</a></i><i><a href="pthread_mutexattr_getprotocol.html">pthread_mutexattr_getprotocol()</a></i><i><a href="pthread_mutexattr_setprioceiling.html">pthread_mutexattr_setprioceiling()</a></i><i><a href="pthread_mutexattr_setprotocol.html">pthread_mutexattr_setprotocol()</a></i><i><a href="pthread_setschedparam.html">pthread_setschedparam()</a></i></pre><p><h4><a name = "tag_000_010_002">&nbsp;</a>Thread-safety</h4><p>All interfaces defined by this specification will be thread-safe,except that the following interfaces need not be thread-safe:<h5><a name = "tag_000_010_002_001">&nbsp;</a>POSIX Interfaces</h5><p><pre><i><a href="asctime.html">asctime()</a></i><i><a href="ctime.html">ctime()</a></i><i><a href="getc_unlocked.html">getc_unlocked()</a></i><i><a href="getchar_unlocked.html">getchar_unlocked()</a></i><i><a href="getgrgid.html">getgrgid()</a></i><i><a href="getgrnam.html">getgrnam()</a></i><i><a href="getlogin.html">getlogin()</a></i><i><a href="getopt.html">getopt()</a></i><i><a href="getpwnam.html">getpwnam()</a></i><i><a href="getpwuid.html">getpwuid()</a></i><i><a href="gmtime.html">gmtime()</a></i><i><a href="localtime.html">localtime()</a></i><i><a href="putc_unlocked.html">putc_unlocked()</a></i><i><a href="putchar_unlocked.html">putchar_unlocked()</a></i><i><a href="rand.html">rand()</a></i><i><a href="readdir.html">readdir()</a></i><i><a href="strtok.html">strtok()</a></i><i><a href="ttyname.html">ttyname()</a></i></pre><p><h5><a name = "tag_000_010_002_002">&nbsp;</a>X/Open Interfaces</h5><p><pre><i><a href="basename.html">basename()</a></i><i><a href="catgets.html">catgets()</a></i><i><a href="dbm_clearerr.html">dbm_clearerr()</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_error.html">dbm_error()</a></i><i><a href="dbm_fetch.html">dbm_fetch()</a></i><i><a href="dbm_firstkey.html">dbm_firstkey()</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="dirname.html">dirname()</a></i><i><a href="drand48.html">drand48()</a></i><i><a href="ecvt.html">ecvt()</a></i><i><a href="encrypt.html">encrypt()</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="fcvt.html">fcvt()</a></i><i><a href="gamma.html">gamma()</a></i><i><a href="gcvt.html">gcvt()</a></i><i><a href="getdate.html">getdate()</a></i><i><a href="getenv.html">getenv()</a></i><i><a href="getgrent.html">getgrent()</a></i><i><a href="getpwent.html">getpwent()</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="l64a.html">l64a()</a></i><i><a href="lgamma.html">lgamma()</a></i><i><a href="lrand48.html">lrand48()</a></i><i><a href="mrand48.html">mrand48()</a></i><i><a href="nl_langinfo.html">nl_langinfo()</a></i><i><a href="ptsname.html">ptsname()</a></i><i><a href="putenv.html">putenv()</a></i><i><a href="pututxline.html">pututxline()</a></i><i><a href="setgrent.html">setgrent()</a></i><i><a href="setkey.html">setkey()</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></pre><p>The interfaces<i><a href="ctermid.html">ctermid()</a></i>and<i><a href="tmpnam.html">tmpnam()</a></i>need not be thread-safe if passed a NULL argument.<p>The interfaces in the Legacy Feature Group need not be thread-safe.<p>Implementations will provide internal synchronisation as necessaryin order to satisfy this requirement.<h4><a name = "tag_000_010_003">&nbsp;</a>Thread Implementation Models</h4><p>There are various thread implementation models.At one end of the spectrum is the &quot;library-thread model&quot;.In such a model, the threads of a process are not visible to theoperating system kernel, and the threads are not kernel scheduledentities.The process is the only kernel scheduled entity.The process is scheduled onto the processor by the kernel according tothe scheduling attributes of the process.The threads are scheduled onto the single kernel scheduled entity (theprocess) by the run-time library according to the schedulingattributes of the threads.A problem with this model is that it constrains concurrency.Since there is only one kernel scheduled entity (namely, the process),only one thread per process can execute at a time.If the thread that is executing blocks on I/O, then the whole processblocks.<p>At the other end of the spectrum is the &quot;kernel-thread model&quot;.In this model, all threads are visible to the operating system kernel.Thus, all threads are kernel scheduled entities, and all threads canconcurrently execute.The threads are scheduled onto processors by the kernel according tothe scheduling attributes of the threads.The drawback to this model is that the creation and management of thethreads entails operating system calls, as opposed to subroutinecalls, which makes kernel threads heavier weight than library threads.<p>Hybrids of these two models are common.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -