pthreadlib.html

来自「Vxworks API操作系统和驱动程序设计API。压缩的HTML文件」· HTML 代码 · 共 1,229 行 · 第 1/5 页

HTML
1,229
字号
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/pthreadLib.html - generated by refgen from pthreadLib.c --> <title> pthreadLib </title></head><body bgcolor="#FFFFFF"> <hr><a name="top"></a><p align=right><a href="libIndex.htm"><i>VxWorks API Reference :  OS Libraries</i></a></p></blockquote><h1>pthreadLib</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>pthreadLib</strong> - POSIX 1003.1c thread library interfaces </p></blockquote><h4>ROUTINES</h4><blockquote><p><p><b><a href="./pthreadLib.html#pthreadLibInit">pthreadLibInit</a>(&nbsp;)</b>  -  initialize POSIX threads support<br><b><a href="./pthreadLib.html#pthread_sigmask">pthread_sigmask</a>(&nbsp;)</b>  -  change and/or examine calling thread's signal mask (POSIX)<br><b><a href="./pthreadLib.html#pthread_kill">pthread_kill</a>(&nbsp;)</b>  -  send a signal to a thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutexattr_init">pthread_mutexattr_init</a>(&nbsp;)</b>  -  initialize mutex attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutexattr_destroy">pthread_mutexattr_destroy</a>(&nbsp;)</b>  -  destroy mutex attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutexattr_setprotocol">pthread_mutexattr_setprotocol</a>(&nbsp;)</b>  -  set protocol attribute in mutex attribut object (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutexattr_getprotocol">pthread_mutexattr_getprotocol</a>(&nbsp;)</b>  -  get value of protocol in mutex attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutexattr_setprioceiling">pthread_mutexattr_setprioceiling</a>(&nbsp;)</b>  -  set prioceiling attribute in mutex attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutexattr_getprioceiling">pthread_mutexattr_getprioceiling</a>(&nbsp;)</b>  -  get the current value of the prioceiling attribute in a mutex attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutex_getprioceiling">pthread_mutex_getprioceiling</a>(&nbsp;)</b>  -  get the value of the prioceiling attribute of a mutex (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutex_setprioceiling">pthread_mutex_setprioceiling</a>(&nbsp;)</b>  -  dynamically set the prioceiling attribute of a mutex (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutex_init">pthread_mutex_init</a>(&nbsp;)</b>  -  initialize mutex from attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutex_destroy">pthread_mutex_destroy</a>(&nbsp;)</b>  -  destroy a mutex (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutex_lock">pthread_mutex_lock</a>(&nbsp;)</b>  -  lock a mutex (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutex_trylock">pthread_mutex_trylock</a>(&nbsp;)</b>  -  lock mutex if it is available (POSIX)<br><b><a href="./pthreadLib.html#pthread_mutex_unlock">pthread_mutex_unlock</a>(&nbsp;)</b>  -  unlock a mutex (POSIX)<br><b><a href="./pthreadLib.html#pthread_condattr_init">pthread_condattr_init</a>(&nbsp;)</b>  -  initialize a condition attribute object (POSIX)<br><b><a href="./pthreadLib.html#pthread_condattr_destroy">pthread_condattr_destroy</a>(&nbsp;)</b>  -  destroy a condition attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_cond_init">pthread_cond_init</a>(&nbsp;)</b>  -  initialize condition variable (POSIX)<br><b><a href="./pthreadLib.html#pthread_cond_destroy">pthread_cond_destroy</a>(&nbsp;)</b>  -  destroy a condition variable (POSIX)<br><b><a href="./pthreadLib.html#pthread_cond_signal">pthread_cond_signal</a>(&nbsp;)</b>  -  unblock a thread waiting on a condition (POSIX)<br><b><a href="./pthreadLib.html#pthread_cond_broadcast">pthread_cond_broadcast</a>(&nbsp;)</b>  -  unblock all threads waiting on a condition (POSIX)<br><b><a href="./pthreadLib.html#pthread_cond_wait">pthread_cond_wait</a>(&nbsp;)</b>  -  wait for a condition variable (POSIX)<br><b><a href="./pthreadLib.html#pthread_cond_timedwait">pthread_cond_timedwait</a>(&nbsp;)</b>  -  wait for a condition variable with a timeout (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_setscope">pthread_attr_setscope</a>(&nbsp;)</b>  -  set contention scope for thread attributes (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_getscope">pthread_attr_getscope</a>(&nbsp;)</b>  -  get contention scope from thread attributes (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_setinheritsched">pthread_attr_setinheritsched</a>(&nbsp;)</b>  -  set inheritsched attribute in thread attribute object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_getinheritsched">pthread_attr_getinheritsched</a>(&nbsp;)</b>  -  get current value if inheritsched attribute in thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_setschedpolicy">pthread_attr_setschedpolicy</a>(&nbsp;)</b>  -  set schedpolicy attribute in thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_getschedpolicy">pthread_attr_getschedpolicy</a>(&nbsp;)</b>  -  get schedpolicy attribute from thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_setschedparam">pthread_attr_setschedparam</a>(&nbsp;)</b>  -  set schedparam attribute in thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_getschedparam">pthread_attr_getschedparam</a>(&nbsp;)</b>  -  get value of schedparam attribute from thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_getschedparam">pthread_getschedparam</a>(&nbsp;)</b>  -  get value of schedparam attribute from a thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_setschedparam">pthread_setschedparam</a>(&nbsp;)</b>  -  dynamically set schedparam attribute for a thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_init">pthread_attr_init</a>(&nbsp;)</b>  -  initialize thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_destroy">pthread_attr_destroy</a>(&nbsp;)</b>  -  destroy a thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_setname">pthread_attr_setname</a>(&nbsp;)</b>  -  set name in thread attribute object<br><b><a href="./pthreadLib.html#pthread_attr_getname">pthread_attr_getname</a>(&nbsp;)</b>  -  get name of thread attribute object<br><b><a href="./pthreadLib.html#pthread_attr_setstacksize">pthread_attr_setstacksize</a>(&nbsp;)</b>  -  set stacksize attribute in thread attributes<br><b><a href="./pthreadLib.html#pthread_attr_getstacksize">pthread_attr_getstacksize</a>(&nbsp;)</b>  -  get stack value of stacksize attribute from thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_setstackaddr">pthread_attr_setstackaddr</a>(&nbsp;)</b>  -  set stackaddr attribute in thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_getstackaddr">pthread_attr_getstackaddr</a>(&nbsp;)</b>  -  get value of stackaddr attribute from thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_setdetachstate">pthread_attr_setdetachstate</a>(&nbsp;)</b>  -  set detachstate attribute in thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_attr_getdetachstate">pthread_attr_getdetachstate</a>(&nbsp;)</b>  -  get value of detachstate attribute from thread attributes object (POSIX)<br><b><a href="./pthreadLib.html#pthread_create">pthread_create</a>(&nbsp;)</b>  -  create a thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_detach">pthread_detach</a>(&nbsp;)</b>  -  dynamically detach a thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_join">pthread_join</a>(&nbsp;)</b>  -  wait for a thread to terminate (POSIX)<br><b><a href="./pthreadLib.html#pthread_exit">pthread_exit</a>(&nbsp;)</b>  -  terminate a thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_equal">pthread_equal</a>(&nbsp;)</b>  -  compare thread IDs (POSIX)<br><b><a href="./pthreadLib.html#pthread_self">pthread_self</a>(&nbsp;)</b>  -  get the calling thread's ID (POSIX)<br><b><a href="./pthreadLib.html#pthread_once">pthread_once</a>(&nbsp;)</b>  -  dynamic package initialization (POSIX)<br><b><a href="./pthreadLib.html#pthread_key_create">pthread_key_create</a>(&nbsp;)</b>  -  create a thread specific data key (POSIX)<br><b><a href="./pthreadLib.html#pthread_setspecific">pthread_setspecific</a>(&nbsp;)</b>  -  set thread specific data (POSIX)<br><b><a href="./pthreadLib.html#pthread_getspecific">pthread_getspecific</a>(&nbsp;)</b>  -  get thread specific data (POSIX)<br><b><a href="./pthreadLib.html#pthread_key_delete">pthread_key_delete</a>(&nbsp;)</b>  -  delete a thread specific data key (POSIX)<br><b><a href="./pthreadLib.html#pthread_cancel">pthread_cancel</a>(&nbsp;)</b>  -  cancel execution of a thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_setcancelstate">pthread_setcancelstate</a>(&nbsp;)</b>  -  set cancellation state for calling thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_setcanceltype">pthread_setcanceltype</a>(&nbsp;)</b>  -  set cancellation type for calling thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_testcancel">pthread_testcancel</a>(&nbsp;)</b>  -  create a cancellation point in the calling thread (POSIX)<br><b><a href="./pthreadLib.html#pthread_cleanup_push">pthread_cleanup_push</a>(&nbsp;)</b>  -  pushes a routine onto the cleanup stack (POSIX)<br><b><a href="./pthreadLib.html#pthread_cleanup_pop">pthread_cleanup_pop</a>(&nbsp;)</b>  -  pop a cleanup routine off the top of the stack (POSIX)<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p>This library provides an implementation of POSIX 1003.1c threads for VxWorks.This provides an increased level of compatibility between VxWorks applicationsand those written for other operating systems that support the POSIX threadsmodel (often called <i>pthreads</i>).<p>VxWorks is a task based operating system, rather than one implementing theprocess model in the POSIX sense. As a result of this, there are a fewrestrictions in the implementation, but in general, since tasks are roughlyequivalent to threads, the <i>pthreads</i> support maps well onto VxWorks.The restrictions are explained in more detail in the following paragraphs.<p></blockquote><h4>CONFIGURATION</h4><blockquote><p>To add POSIX threads support to a system, the component <b>INCLUDE_POSIX_PTHREADS</b>must be added.<p>Threads support also requires the POSIX scheduler to be included (see<b><a href="./schedPxLib.html#top">schedPxLib</a></b> for more detail). <p></blockquote><h4>THREADS</h4><blockquote><p>A thread is essentially a VxWorks task, with some additional characteristics.The first is detachability, where the creator of a thread can optionally blockuntil the thread exits. The second is cancelability, where one task or threadcan cause a thread to exit, possibly calling cleanup handlers. The next isprivate data, where data private to a thread is created, accessed and deletedvia keys. Each thread has a unique ID. A thread's ID is different than it'sVxWorks task ID.<p></blockquote><h4>MUTEXES</h4><blockquote><p>Included with the POSIX threads facility is a mutual exclusion facility, or<i>mutex</i>. These are functionally similar to the VxWorks mutex semaphores (see<b><a href="./semMLib.html#top">semMLib</a></b> for more detail), and in fact are implemented using a VxWorksmutex semaphore. The advantage they offer, like all of the POSIX libraries,is the ability to run software designed for POSIX platforms under VxWorks.<p>There are two types of locking protocols available, <b>PTHREAD_PRIO_INHERIT</b> and<b>PTHREAD_PRIO_PROTECT</b>. <b>PTHREAD_PRIO_INHERIT</b> maps to a semaphore create with<b>SEM_PRIO_INHERIT</b> set (see <b>semMCreate</b> for more detail). A thread locking amutex created with its protocol attribute set to <b>PTHREAD_PRIO_PROTECT</b> has itspriority elevated to that of of the prioceiling attribute of the mutex. Whenthe mutex is unlocked, the priority of the calling thread is restored to itsprevious value.<p></blockquote><h4>CONDITION VARIABLES</h4><blockquote><p>Condition variables are another synchronization mechanism that is includedin the POSIX threads library. A condition variable allows threadsto block until some condition is met. There are really only two basicoperations that a condition variable can be involved in: waiting andsignalling. Condition variables are always associated with a mutex.<p>A thread can wait for a condition to become true by taking the mutex andthen calling <b><a href="./pthreadLib.html#pthread_cond_wait">pthread_cond_wait</a>(&nbsp;)</b>. That function will release the mutex andwait for the condition to be signalled by another thread. When the conditionis signalled, the function will re-acquire the mutex and return to the caller.<p>Condition variable support two types of signalling: single thread wake-up using<b><a href="./pthreadLib.html#pthread_cond_signal">pthread_cond_signal</a>(&nbsp;)</b>, and multiple thread wake-up using<b><a href="./pthreadLib.html#pthread_cond_broadcast">pthread_cond_broadcast</a>(&nbsp;)</b>. The latter of these will unblock all threads thatwere waiting on the specified condition variable.<p>It should be noted that condition variable signals are not related to POSIXsignals. In fact, they are implemented using VxWorks semaphores.<p></blockquote><h4>RESOURCE COMPETITION</h4><blockquote><p>All tasks, and therefore all POSIX threads, compete for CPU time together. Forthat reason the contention scope thread attribute is always<b>PTHREAD_SCOPE_SYSTEM</b>.<p></blockquote><h4>NO VXWORKS EQUIVALENT</h4><blockquote><p>Since there is no notion of a process (in the POSIX sense), there is nonotion of sharing of locks (mutexes) and condition variables between processes.As a result, the POSIX symbol <b>_POSIX_THREAD_PROCESS_SHARED</b> is not defined inthis implementation, and the routines <b>pthread_condattr_getpshared(&nbsp;)</b>,<b>pthread_condattr_setpshared(&nbsp;)</b>, <b>pthread_mutexattr_getpshared(&nbsp;)</b> are notimplemented.<p>Also, since there are no processes in VxWorks, <b>fork(&nbsp;)</b>, <b>wait(&nbsp;)</b>, and<b>pthread_atfork(&nbsp;)</b> are unimplemented.<p>VxWorks does not have password, user, or group databases, therefore there areno implementations of <b>getlogin(&nbsp;)</b>, <b>getgrgid(&nbsp;)</b>, <b>getpwnam(&nbsp;)</b>, <b>getpwuid(&nbsp;)</b>,<b>getlogin_r(&nbsp;)</b>, <b>getgrgid_r(&nbsp;)</b>, <b>getpwnam_r(&nbsp;)</b>,  and <b>getpwuid_r(&nbsp;)</b>.<p></blockquote><h4>SCHEDULING</h4><blockquote><p>The default scheduling policy for a created thread is inherited from the systemsetting at the time of creation.<p>Scheduling policies under VxWorks are global; they are not set per-thread,as the POSIX model describes. As a result, the <i>pthread</i> scheduling routines,as well as the POSIX scheduling routines native to VxWorks, do not allow youto change the scheduling policy. Under VxWorks you may set the schedulingpolicy in a thread, but if it does not match the system's scheduling policy,an error is returned.<p>The detailed explanation for why this error occurs is a bit convoluted:technically the scheduling policy is an attribute of a thread (in that thereare <b><a href="./pthreadLib.html#pthread_attr_getschedpolicy">pthread_attr_getschedpolicy</a>(&nbsp;)</b> and <b><a href="./pthreadLib.html#pthread_attr_setschedpolicy">pthread_attr_setschedpolicy</a>(&nbsp;)</b> functionsthat define what the thread's scheduling policy will be once it is created,and not what any thread should do at the time they are called). A situationarises where the scheduling policy in force at the time of a thread'screation is not the same as set in its attributes. In this case<b><a href="./pthreadLib.html#pthread_create">pthread_create</a>(&nbsp;)</b> fails with an otherwise undocumented error <b>ENOTTY</b>.<p>The bottom line is that under VxWorks, if you wish to specify the schedulingpolicy of a thread, you must set the desired global scheduling policy to match.Threads must then adhere to that scheduling policy, or use the<b>PTHREAD_INHERIT_SCHED</b> mode to inherit the current mode and creator's priority.<p></blockquote><h4>CREATION AND CANCELLATION</h4><blockquote><p>Each time a thread is created, the <i>pthreads</i> library allocates resources onbehalf of it. Each time a VxWorks task (i.e. one not created by the<b><a href="./pthreadLib.html#pthread_create">pthread_create</a>(&nbsp;)</b> function) uses a POSIX threads feature such as threadprivate data or pushes a cleanup handler, the <i>pthreads</i> library createsresources on behalf of that task as well.<p>Asynchronous thread cancellation is accomplished by way of a signal. Aspecial signal, SIGCANCEL, has been set aside in this version of VxWorks forthis purpose. Applications should take care not to block or handle SIGCANCEL.<p></blockquote><h4>SUMMARY MATRIX</h4><blockquote><p><p><table><tr valign=top><th align=left><b><i>pthread</i> function</b> </th><th align=left> <b>Implemented?</b> </th><th align=left> <b>Note(s)</b></tr><tr><td colspan="3"><hr></tr><tr valign=top><td align=left><b>pthread_attr_destroy</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_getdetachstate</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_getinheritsched</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_getschedparam</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_getschedpolicy</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_getscope</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_getstackaddr</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_getstacksize</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_init</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_setdetachstate</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_setinheritsched</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_setschedparam</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_setschedpolicy</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_setscope</b> </td><td align=left> Yes </td><td align=left> 2</tr><tr valign=top><td align=left><b>pthread_attr_setstackaddr</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_attr_setstacksize</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_atfork</b> </td><td align=left> No </td><td align=left> 1</tr><tr valign=top><td align=left><b>pthread_cancel</b> </td><td align=left> Yes </td><td align=left> 5</tr><tr valign=top><td align=left><b>pthread_cleanup_pop</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_cleanup_push</b> </td><td align=left> Yes </td><td align=left></tr><tr valign=top><td align=left><b>pthread_condattr_destroy</b> </td><td align=left> Yes </td><td align=left></tr>

⌨️ 快捷键说明

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