


CV_CREATE(3L)     LIGHTWEIGHT PROCESSES LIBRARY     CV_CREATE(3L)



NAME
     cv_create,  cv_destroy,  cv_wait,  cv_notify,  cv_broadcast,
     cv_send,  cv_enumerate, cv_waiters, SAMECV - manage LWP con-
     dition variables

SYNOPSIS
     #include <lwp/lwp.h>

     cv_t cv_create(cv, mid)
     cv_t *cv;
     mon_t mid;

     int cv_destroy(cv)
     cv_t cv;

     int cv_wait(cv)
     cv_t cv;

     int cv_notify(cv)
     cv_t cv;

     int cv_send(cv, tid)
     cv_t cv;
     lwp_t tid

     int cv_broadcast(cv)
     cv_t cv;

     int cv_enumerate(vec, maxsize)
     cv_t vec[];    /* will contain list of all conditions */
     int maxsize;   /* maximum size of vec */

     int cv_waiters(cv, vec, maxsize)
     cv_t cv;       /* condition variable being interrogated */
     thread_t vec[];     /* which threads are blocked on cv */
     int maxsize;   /* maximum size of vec */

     SAMECV(c1, c2)

DESCRIPTION
     Condition variables are useful  for  synchronization  within
     monitors.    By   waiting   on  a  condition  variable,  the
     currently-held monitor (a condition variable must _a_l_w_a_y_s  be
     used within a monitor) is released atomically and the invok-
     ing thread is suspended.  When monitors are nested,  monitor
     locks other than the current one are retained by the thread.
     At some later point, a different thread may awaken the wait-
     ing  thread by issuing a notification on the condition vari-
     able.  When the notification occurs, the waiting thread will
     queue  to  reacquire the monitor it gave up.  It is possible
     to have different condition variables operating  within  the
     same monitor to allow selectivity in waking up threads.



Sun Release 4.1   Last change: 21 January 1990                  1






CV_CREATE(3L)     LIGHTWEIGHT PROCESSES LIBRARY     CV_CREATE(3L)



     cv_create() creates a new condition  variable  (returned  in
     _c_v)  which  is bound to the monitor specified by _m_i_d.  It is
     illegal to access (using cv_wait(),  cv_notify(),  cv_send()
     or cv_broadcast()) a condition variable from a monitor other
     than the one it is bound to.  cv_destroy() removes a  condi-
     tion variable.

     cv_wait() blocks the current thread and releases the monitor
     lock  associated  with the condition (which must also be the
     monitor lock most recently acquired by the  thread).   Other
     monitor  locks  held  by  the  thread are not affected.  The
     blocked thread is enqueued by its scheduling priority on the
     condition.

     cv_notify() awakens at most one thread blocked on the condi-
     tion  variable  and  causes the awakened thread to queue for
     access to the monitor released at the time it waited on  the
     condition.   It can be dangerous to use cv_notify() if there
     is a possibility that the thread being awakened  is  one  of
     several threads that are waiting on a condition variable and
     the awakened thread may not be the one  intended.   In  this
     case, use of cv_broadcast() is recommended.

     cv_broadcast() is the same as cv_notify()  except  that  _a_l_l
     threads  blocked  on  the  condition  variable are awakened.
     cv_notify() and cv_broadcast() do nothing if  no  thread  is
     waiting   on   the  condition.   For  both  cv_notify()  and
     cv_broadcast(), the currently held monitor must  agree  with
     the one bound to the condition by cv_create().

     cv_send() is like cv_notify()  except  that  the  particular
     thread  tid  is  awakened.   If this thread is not currently
     blocked on the condition, cv_send() reports an error.

     cv_enumerate() lists the ID of all of  the  condition  vari-
     ables.   The value returned is the total number of condition
     variables.  The vector supplied is filled in with  the  ID's
     of  condition variables.  cv_waiters() lists the ID's of the
     threads blocked on the condition variable _c_v and returns the
     number  of  threads  blocked on _c_v.  For both cv_enumerate()
     and cv_waiters(), _m_a_x_s_i_z_e is used  to  avoid  exceeding  the
     capacity  of  the  list _v_e_c.  If the number of entries to be
     filled is greater than _m_a_x_s_i_z_e,  only  _m_a_x_s_i_z_e  entries  are
     filled  in  _v_e_c.  It is legal in both of these primitives to
     specify a _m_a_x_s_i_z_e of 0.

     SAMECV is a convenient predicate used to compare two  condi-
     tion variables for equality.

RETURN VALUES
     cv_create(), cv_destroy(), cv_send(), cv_wait(), cv_notify()
     and cv_broadcast() return:



Sun Release 4.1   Last change: 21 January 1990                  2






CV_CREATE(3L)     LIGHTWEIGHT PROCESSES LIBRARY     CV_CREATE(3L)



     0    on success.

     -1   on failure and set errno to indicate the error.

     cv_enumerate() returns the total number of  condition  vari-
     ables.

     cv_waiters() returns the number of threads blocked on a con-
     dition variable.

ERRORS
     cv_destroy() will fail if one or more of  the  following  is
     true:

     LE_INUSE            Attempt to  destroy  condition  variable
                         being waited on by a thread.

     LE_NONEXIST         Attempt to destroy  non-existent  condi-
                         tion variable.

     cv_wait() will fail if one or more of the following is true:

     LE_NONEXIST         Attempt to wait on  non-existent  condi-
                         tion variable.

     LE_NOTOWNED         Attempt to wait on a  condition  without
                         possessing the correct monitor lock.

     cv_notify() will fail if one or more  of  the  following  is
     true:

     LE_NONEXIST         Attempt to notify non-existent condition
                         variable.

     LE_NOTOWNED         Attempt  to  notify  condition  variable
                         without possessing the correct monitor.

     cv_send() will fail if one or more of the following is true:

     LE_NONEXIST         Attempt to awaken non-existent condition
                         variable.

     LE_NOTOWNED         Attempt  to  awaken  condition  variable
                         without  possessing  the correct monitor
                         lock.

     LE_NOWAIT           The specified thread  is  not  currently
                         blocked on the condition.

     cv_broadcast() will fail if one or more of the following  is
     true:




Sun Release 4.1   Last change: 21 January 1990                  3






CV_CREATE(3L)     LIGHTWEIGHT PROCESSES LIBRARY     CV_CREATE(3L)



     LE_NONEXIST         Attempt to broadcast non-existent condi-
                         tion variable.

     LE_NOTOWNED         Attempt to broadcast  condition  without
                         possessing the correct monitor lock.

SEE ALSO
     mon_create(3L)















































Sun Release 4.1   Last change: 21 January 1990                  4



