Skip to content
Snippets Groups Projects
NuttxUserGuide.html 246 KiB
Newer Older
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadmutexlock">2.9.34 pthread_mutex_lock</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_mutex_lock(pthread_mutex_t *mutex);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
patacongo's avatar
patacongo committed
   The mutex object referenced by mutex is locked by calling <code>pthread_mutex_lock()</code>.
   If the mutex is already locked, the calling thread blocks until the mutex
   becomes available. This operation returns with the mutex object referenced
   by mutex in the locked state with the calling thread as its owner.
</p>
<p>
   If the mutex type is <code>PTHREAD_MUTEX_NORMAL</code>, deadlock detection is not provided.
patacongo's avatar
patacongo committed
   Attempting to re-lock the mutex causes deadlock. If a thread attempts to unlock
patacongo's avatar
patacongo committed
   a mutex that it has not locked or a mutex which is unlocked, undefined behavior
   results.
</p>
<p>
   In NuttX, <code>PTHREAD_MUTEX_NORMAL</code> is not implemented.  Rather, the behavior described
   for <code>PTHREAD_MUTEX_ERRORCHECK</code> is the <i>normal</i> behavior.
</p>
<p>
   If the mutex type is <code>PTHREAD_MUTEX_ERRORCHECK</code>, then error checking is provided.
patacongo's avatar
patacongo committed
   If a thread attempts to re-lock a mutex that it has already locked, an error
patacongo's avatar
patacongo committed
   will be returned. If a thread attempts to unlock a mutex that it has not
   locked or a mutex which is unlocked, an error will be returned.
</p>
<p>
   If the mutex type is <code>PTHREAD_MUTEX_RECURSIVE</code>, then the mutex maintains the concept
   of a lock count. When a thread successfully acquires a mutex for the first time,
patacongo's avatar
patacongo committed
   the lock count is set to one. Every time a thread re-locks this mutex, the lock count
patacongo's avatar
patacongo committed
   is incremented by one. Each time the thread unlocks the mutex, the lock count is
   decremented by one. When the lock count reaches zero, the mutex becomes available
   for other threads to acquire. If a thread attempts to unlock a mutex that it has
   not locked or a mutex which is unlocked, an error will be returned.
</p>
<p>
   If a signal is delivered to a thread waiting for a mutex, upon return from
   the signal handler the thread resumes waiting for the mutex as if it was
   not interrupted.
</p>
patacongo's avatar
patacongo committed
<p>
<b>Input Parameters:</b>
<p>
<ul>
patacongo's avatar
patacongo committed
  <li><code>mutex</code>.  A reference to the mutex to be locked.</li>
patacongo's avatar
patacongo committed
</ul>
<p>
<b>Returned Values:</b>
<p>
patacongo's avatar
patacongo committed
If successful, the <I>pthread_mutex_lock()</I> function will return zero (<I>OK</I>).
Otherwise, an error number will be returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
patacongo's avatar
patacongo committed
<p>Note that this function will never return the error EINTR.</p>
patacongo's avatar
patacongo committed
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadmutextrylock">2.9.35 pthread_mutex_trylock</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_mutex_trylock(pthread_mutex_t *mutex);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
patacongo's avatar
patacongo committed
   The function pthread_mutex_trylock() is identical to <a href="#pthreadmutexlock"><code>pthread_mutex_lock()</code></a>
   except that if the mutex object referenced by mutex is currently locked
   (by any thread, including the current thread), the call returns immediately
   with the errno <code>EBUSY</code>.
<p>
   If a signal is delivered to a thread waiting for a mutex, upon return from
   the signal handler the thread resumes waiting for the mutex as if it was
   not interrupted.
</p>
patacongo's avatar
patacongo committed
<p>
<b>Input Parameters:</b>
<p>
<ul>
patacongo's avatar
patacongo committed
  <li><code>mutex</code>.  A reference to the mutex to be locked.</li>
patacongo's avatar
patacongo committed
</ul>
<p>
<b>Returned Values:</b>
<p>
patacongo's avatar
patacongo committed
If successful, the <I>pthread_mutex_trylock()</I> function will return zero (<I>OK</I>).
Otherwise, an error number will be returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
patacongo's avatar
patacongo committed
<p>Note that this function will never return the error EINTR.</p>
patacongo's avatar
patacongo committed
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadmutexunlock">2.9.36 pthread_mutex_unlock</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_mutex_unlock(pthread_mutex_t *mutex);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
patacongo's avatar
patacongo committed
   The <code>pthread_mutex_unlock()</code> function releases the mutex object referenced
   by mutex. The manner in which a mutex is released is dependent upon the
   mutex's type attribute. If there are threads blocked on the mutex object
   referenced by mutex when <code>pthread_mutex_unlock()</code> is called, resulting in
   the mutex becoming available, the scheduling policy is used to determine
   which thread shall acquire the mutex. (In the case of <code>PTHREAD_MUTEX_RECURSIVE</code>
   mutexes, the mutex becomes available when the count reaches zero and the
   calling thread no longer has any locks on this mutex).
</p>
<p>
   If a signal is delivered to a thread waiting for a mutex, upon return from
   the signal handler the thread resumes waiting for the mutex as if it was
   not interrupted.
</p>
patacongo's avatar
patacongo committed
<b>Input Parameters:</b>
<p>
<ul>
patacongo's avatar
patacongo committed
  <li><code>param<code>.</li>
patacongo's avatar
patacongo committed
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_mutex_unlock()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
patacongo's avatar
patacongo committed
<p>Note that this function will never return the error EINTR.</p>
patacongo's avatar
patacongo committed
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadconaddrinit">2.9.37 pthread_condattr_init</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_condattr_init(pthread_condattr_t *attr);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_condattr_init()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadocndattrdestroy">2.9.38 pthread_condattr_destroy</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_condattr_destroy(pthread_condattr_t *attr);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_condattr_destroy()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondinit">2.9.39 pthread_cond_init</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_cond_init()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadconddestroy">2.9.40 pthread_cond_destroy</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_destroy(pthread_cond_t *cond);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_cond_destroy()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondbroadcast">2.9.41 pthread_cond_broadcast</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_broadcast(pthread_cond_t *cond);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_cond_broadcast()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondsignal">2.9.42 pthread_cond_signal</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_signal(pthread_cond_t *dond);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
<b>Returned Values:</b>
<p>
If successful, the <I>pthread_cond_signal()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondwait">2.9.43 pthread_cond_wait</a></H3>
patacongo's avatar
patacongo committed
<p>
<b>Function Prototype:</b>
<p>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
patacongo's avatar
patacongo committed
<p>
<b>Description:</b>
<p>
<b>Input Parameters:</b>
<p>
<ul>
  <li><code>To be provided</code>.</li>
</ul>
<p>
patacongo's avatar
patacongo committed
  <b>Returned Values:</b>
patacongo's avatar
patacongo committed
<p>
If successful, the <I>pthread_cond_wait()</I> function will return
patacongo's avatar
patacongo committed
zero (<I>OK</I>).  Otherwise, an error number will be
returned to indicate the error:
patacongo's avatar
patacongo committed
<p>
<ul>
  <li><code>To be provided</code>. </li>
</ul>
<b>Assumptions/Limitations:</b>
<p>
<b>POSIX Compatibility:</b> Comparable to the POSIX
patacongo's avatar
patacongo committed
interface of the same name.

<H3><a name="pthreadcondtimedwait">2.9.44 pthread_cond_timedwait</a></H3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
patacongo's avatar
patacongo committed
    #include &lt;pthread.h&gt;
    int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
				  const struct timespec *abstime);
patacongo's avatar
patacongo committed
</pre>
<p>
  <b>Description:</b>
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
patacongo's avatar
patacongo committed
  <li><code>To be provided</code>.</li>
patacongo's avatar
patacongo committed
</ul>
<p>
  <b>Returned Values:</b>
</p>
<p>
  If successful, the <code>pthread_cond_timedwait()</code> function will return
  zero (<code>OK</code>).  Otherwise, an error number will be
  returned to indicate the error:
</p>
<ul>
patacongo's avatar
patacongo committed
  <li><code>To be provided</code>. </li>
patacongo's avatar
patacongo committed
</ul>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierattrinit">2.9.45 pthread_barrierattr_init</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrierattr_init(FAR pthread_barrierattr_t *attr);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrierattr_init()</code> function will initialize a barrier
  attribute object <code>attr</code> with the default value for all of the attributes
  defined by the implementation.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li>
    <code>attr</code>. Barrier attributes to be initialized.
</li>
</ul>
<p>
  <b>Returned Values:</b>
  0 (<code>OK</code>) on success or <code>EINVAL</code> if <code>attr</code> is invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierattrdestroy">2.9.46 pthread_barrierattr_destroy</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrierattr_destroy(FAR pthread_barrierattr_t *attr);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrierattr_destroy()</code> function will destroy a barrier attributes object.
  A destroyed attributes object can be reinitialized using <code>pthread_barrierattr_init()</code>;
  the results of otherwise referencing the object after it has been destroyed are undefined.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li>
    <code>attr</code>. Barrier attributes to be destroyed.
</li>
</ul>
<p>
  <b>Returned Values:</b> 0 (OK) on success or EINVAL if attr is invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierattrsetpshared">2.9.47 pthread_barrierattr_setpshared</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrierattr_setpshared(FAR pthread_barrierattr_t *attr, int pshared);
</pre>
<p>
  <b>Description:</b>
  The process-shared attribute is set to <code>PTHREAD_PROCESS_SHARED</code> to permit
  a barrier to be operated upon by any thread that has access to the memory where the
  barrier is allocated.
  If the process-shared attribute is <code>PTHREAD_PROCESS_PRIVATE</code>, the barrier can
  only be operated upon by threads created within the same process as the thread that
  initialized the barrier.
  If threads of different processes attempt to operate on such a barrier, the behavior is undefined.
  The default value of the attribute is <code>PTHREAD_PROCESS_PRIVATE</code>.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li><code>attr</code>. Barrier attributes to be modified.</li>
  <li><code>pshared</code>. The new value of the pshared attribute.</li>
</ul>
<p>
  <b>Returned Values:</b>  0 (<code>OK</code>) on success or <code>EINVAL</code> if either
  <code>attr</code> is invalid or <code>pshared</code> is not one of
  <code>PTHREAD_PROCESS_SHARED</code> or <code>PTHREAD_PROCESS_PRIVATE</code>.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierattrgetpshared">2.9.48 pthread_barrierattr_getpshared</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrierattr_getpshared(FAR const pthread_barrierattr_t *attr, FAR int *pshared);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrierattr_getpshared()</code> function will obtain the value of the
  process-shared attribute from the attributes object referenced by <code>attr</code>.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li><code>attr</code>. Barrier attributes to be queried.</li>
  <li><code>pshared</code>. The location to stored the current value of the pshared attribute.</li>
</ul>
<p>
  <b>Returned Values:</b> 0 (<code>OK</code>) on success or <code>EINVAL</code> if
  either <code>attr</code> or <code>pshared</code> is invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierinit">2.9.49 pthread_barrier_init</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrier_init(FAR pthread_barrier_t *barrier,
                             FAR const pthread_barrierattr_t *attr, unsigned int count);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrier_init()</code> function allocates any resources required to
  use the barrier referenced by <code>barrier</code> and initialized the barrier with
  the attributes referenced by <code>attr</code>. 
  If <code>attr</code> is NULL, the default barrier attributes will be used.
  The results are undefined if <code>pthread_barrier_init()</code> is called when any
  thread is blocked on the barrier.
  The results are undefined if a barrier is used without first being initialized.
  The results are undefined if <code>pthread_barrier_init()</code> is called specifying
  an already initialized barrier.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li>
    <code>barrier</code>.
    The barrier to be initialized.
  </li>
  <li>
    <code>attr</code>.
    Barrier attributes to be used in the initialization.
  </li>
  <li>
    <code>count</code>.
    The count to be associated with the barrier.
    The count argument specifies the number of threads that must call
    <code>pthread_barrier_wait()</code> before any of them successfully return from the call.
    The value specified by count must be greater than zero.
  </li>
</ul>
<p>
  <b>Returned Values:</b>0 (OK) on success or on of the following error numbers:
</p>
<ul>
  <li>
    <code>EAGAIN</code>.
    The system lacks the necessary resources to initialize another barrier.
  </li>
  <li>
    <code>EINVAL</code>.
    The barrier reference is invalid, or the values specified by attr are invalid, or
    the value specified by count is equal to zero.
  </li>
  <li>
    <code>ENOMEM</code>.
    Insufficient memory exists to initialize the barrier.
  </li>
  <li>
    <code>EBUSY</code>.
    The implementation has detected an attempt to reinitialize a barrier while it is in use.
  </li>
</ul>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierdestroy">2.9.50 pthread_barrier_destroy</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrier_destroy(FAR pthread_barrier_t *barrier);
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_barrier_destroy()</code> function destroys the barrier referenced
  by <code>barrie</code> and releases any resources used by the barrier.
  The effect of subsequent use of the barrier is undefined until the barrier is
  reinitialized by another call to <code>pthread_barrier_init()</code>.
  The results are undefined if <code>pthread_barrier_destroy()</code> is called when
  any thread is blocked on the barrier, or if this function is called with an
  uninitialized barrier.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li><code>barrier</code>. The barrier to be destroyed.</li>
</ul>
<p>
  <b>Returned Values:</b> 0 (<code>OK</code>) on success or on of the following error numbers:
</p>
<ul>
  <li>
    <code>EBUSY</code>.
    The implementation has detected an attempt to destroy a barrier while it is in use.
  </li>
  <li>
    <code>EINVAL</code>.
    The value specified by barrier is invalid.
  </li>
</ul>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadbarrierwait">2.9.51 pthread_barrier_wait</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_barrier_wait(FAR pthread_barrier_t *barrier);
</pre>
<p>
  <b>Description:</b>
patacongo's avatar
patacongo committed
  The <code>pthread_barrier_wait()</code> function synchronizes participating
patacongo's avatar
patacongo committed
  threads at the barrier referenced by <code>barrier</code>.
  The calling thread is blocked until the required number of threads have called
  <code>pthread_barrier_wait()</code> specifying the same <code>barrier</code>.
  When the required number of threads have called <code>pthread_barrier_wait()</code>
  specifying the <code>barrier</code>, the constant <code>PTHREAD_BARRIER_SERIAL_THREAD</code>
  will be returned to one unspecified thread and zero will be returned to each of
  the remaining threads.
  At this point, the barrier will be reset to the state it had as a result of the most
  recent <code>pthread_barrier_init()</code> function that referenced it.
</p>
<p>
  The constant <code>PTHREAD_BARRIER_SERIAL_THREAD</code> is defined in 
 <code>pthread.h</code> and its value must be distinct from any other value
  returned by <code>pthread_barrier_wait()</code>.
</p>
<p>
  The results are undefined if this function is called with an uninitialized barrier.
</p>
<p>
  If a signal is delivered to a thread blocked on a barrier, upon return from the
  signal handler the thread will resume waiting at the barrier if the barrier wait
  has not completed.
  Otherwise, the thread will continue as normal from the completed barrier wait.
  Until the thread in the signal handler returns from it, it is unspecified whether
  other threads may proceed past the barrier once they have all reached it.
</p>
<p>
  A thread that has blocked on a barrier will 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 will be determined by the scheduling policy.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<ul>
  <li><code>barrier</code>. The barrier on which to wait.</li>
</ul>
<p>
  <b>Returned Values:</b> 0 (<code>OK</code>) on success or <code>EINVAL</code> if the barrier is not valid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>


<h3><a name="pthreadonce">2.9.52 pthread_once</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;pthread.h&gt;
    int pthread_once(FAR pthread_once_t *once_control, CODE void (*init_routine)(void));
</pre>
<p>
  <b>Description:</b>
  The  first  call to <code>pthread_once()</code> by any thread with a given
  <code>once_control</code>, will call the <code>init_routine()</code> with no arguments.
  Subsequent calls to <code>pthread_once()</code> with the same <code>once_control</code> will have no effect.
  On return from <code>pthread_once()</code>, <code>init_routine()</code> will have completed.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>once_control</code>.
    Determines if <code>init_routine()</code> should be called.
patacongo's avatar
patacongo committed
    <code>once_control</code> should be declared and initialized as follows:
patacongo's avatar
patacongo committed
    <ul><pre>pthread_once_t once_control = PTHREAD_ONCE_INIT;
    </pre></ul>
    <code>PTHREAD_ONCE_INIT</code> is defined in <code>pthread.h</code>.
  </li>
  <li>
    <code>init_routine</code>.
    The initialization routine that will be called once.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
  0 (OK) on success or EINVAL if either once_control or init_routine are invalid.
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadkill">2.9.53 pthread_kill</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;signal.h&gt;
    #include &lt;pthread.h&gt;
    int pthread_kill(pthread_t thread, int signo)
</pre>
<p>
  <b>Description:</b>
  The <code>pthread_kill()</code> system call can be used to send any
  signal to a thread.  See <code>kill()</code> for further information
  as this is just a simple wrapper around the <code>kill()</code>
  function.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>thread</code>.
    The id of the thread to receive the signal. Only positive, non-zero values of <code>tthread</code>t are supported.
  </li>
  <li>
    <code>signo</code>.
    The signal number to send.  If <code>signo</code> is zero, no signal is sent, but all error checking is performed.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
</p>
<p>
  On success, the signal was sent and zero is returned.
  On error one of the following error numbers is returned.
</p>
<ul>
  <li>
    <code>EINVAL</code>.
    An invalid signal was specified.
  </li>
  <li>
    <code>EPERM</code>.
    The thread does not have permission to send the signal to the target thread.
  </li>
  <li>
    <code>ESRCH</code>.
    No thread could be found corresponding to that specified by the given thread ID.
  </li>
  <li>
    <code>ENOSYS</code>.
    Do not support sending signals to process groups.
  </li>
</ul>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>

<h3><a name="pthreadsigmask">2.9.54 pthread_sigmask</a></h3>
patacongo's avatar
patacongo committed
<p>
  <b>Function Prototype:</b>
</p>
<pre>
    #include &lt;signal.h&gt;
    #include &lt;pthread.h&gt;
    int pthread_sigmask(int how, FAR const sigset_t *set, FAR sigset_t *oset);
</pre>
<p>
  <b>Description:</b>
  This function is a simple wrapper around <code>sigprocmask()</code>.
  See the <code>sigprocmask()</code> function description for further information.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>how</code>. How the signal mast will be changed:
    <ul>
      <li>
        <code>SIG_BLOCK</code>:
        The resulting set is the union of the current set and the signal set pointed to by <code>set</code>.
      </li>
      <li>
        <code>SIG_UNBLOCK</code>:
        The resulting set is the intersection of the current set and the complement of the signal set pointed to by <code>set</code>.
      </li>
      <li>
        <code>SIG_SETMASK</code>:
        The resulting set is the signal set pointed to by <code>set</code>.
      </li>
    </ul>
  </li>
  <li>
    <code>set</code>. Location of the new signal mask.
  </li>
  <li>
    <code>oset</code>. Location to store the old signal mask.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
</p>
<p>
patacongo's avatar
patacongo committed
  0 (OK) on success or EINVAL if <code>how</code> is invalid.
patacongo's avatar
patacongo committed
</p>
<p>
  <b>Assumptions/Limitations:</b>
</p>
<p>
  <b>POSIX Compatibility:</b> Comparable to the POSIX interface of the same name.
</p>
patacongo's avatar
patacongo committed

<table width ="100%">
  <tr bgcolor="#e4e4e4">
  <td>
    <a name="Environ"><h2>2.10 Environment Variables</h2></a>
  </td>
  </tr>
</table>

<p><b>Overview</b>.
  NuttX supports environment variables that can be used to control the behavior of programs.
  In the spirit of NuttX the environment variable behavior attempts to emulate the behavior of
patacongo's avatar
patacongo committed
  environment variables in the multi-processing OS:
</p>
<ul>
  <li><b>Task environments</b>.
    When a new task is created using <a href="#taskcreate">task_create</a>, the environment
    of the child task is an inherited, exact copy of the environment of the parent.
    However, after child task has been created, subsequent operations by the child task on
    its environment does not alter the environment of the parent.
    No do operations by the parent effect the child's environment.
    The environments start identical but are independent and may diverge.
  </li>
  <li><b>Thread environments</b>.
    When a pthread is created using <a href="#pthreadcreate">pthread_create</a>, the child
patacongo's avatar
patacongo committed
    thread also inherits that environment of the parent.
    However, the child does not receive a copy of the environment but, rather, shares the same
    environment.
patacongo's avatar
patacongo committed
    Changes to the environment are visible to all threads with the same parentage.
  </li>
</ul>
<p><b>Programming Interfaces</b>.
  The following environment variable programming interfaces are provided by Nuttx and are
  described in detail in the following paragraphs.
</p>
<ul>
  <li><a href="#getenv">2.10.1 <code>getenv</code></a></li>
  <li><a href="#putenv">2.10.2 <code>putenv</code></a></li>
  <li><a href="#clearenv">2.10.3 <code>clearenv</code></a></li>
  <li><a href="#setenv">2.10.4 <code>setenv</code></a></li>
  <li><a href="#unsetenv">2.10.5 <code>unsetenv</code></a></li>
</ul>
<p><b>Disabling Environment Variable Support</b>.
patacongo's avatar
patacongo committed
  All support for environment variables can be disabled by setting <code>CONFIG_DISABLE_ENVIRON</code>
  in the board configuration file.
</p>

<h3><a name="getenv">2.10.1 <code>getenv</code></a></h3>
<p>
  <b>Function Prototype:</b>
</p>
<pre>
  #include &lt;stdlib.h&gt;
  FAR char *getenv(const char *name);
</pre>
<p>
  <b>Description:</b>
    The <code>getenv()</code> function searches the environment list for a string that
    matches the string pointed to by <code>name</code>.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>name</code>.
    The name of the variable to find.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
patacongo's avatar
patacongo committed
   The value of the variable (read-only) or NULL on failure.
<h3><a name="putenv">2.10.2 <code>putenv</code></a></h3>
<p>
  <b>Function Prototype:</b>
</p>
<pre>
  #include &lt;stdlib.h&gt;
  int putenv(char *string);
</pre>
<p>
  <b>Description:</b>
  The <code>putenv()</code> function adds or changes the value of environment variables.
  The argument string is of the form <i>name=value</i>. If name does not already
  exist in  the  environment, then string is added to the environment. If
  name does exist, then the value of name in the environment is changed to
  value.
</p>
<p>
  <b>Input Parameters:</b>
</p>
<p>
<ul>
  <li>
    <code>string</code>
    name=value string describing the environment setting to add/modify.
  </li>
</ul>
<p>
  <b>Returned Values:</b>
patacongo's avatar
patacongo committed
  Zero on success.
<h3><a name="clearenv">2.10.3 <code>clearenv</code></a></h3>
<p>
  <b>Function Prototype:</b>
</p>
<pre>
  #include &lt;stdlib.h&gt;
  int clearenv(void);
</pre>
<p>