Updated: 2022/Sep/29

Please read Privacy Policy. It's for your privacy.


CND(3)                     Library Functions Manual                     CND(3)

NAME
     cnd - condition variable functions

LIBRARY
     POSIX Threads Library (libpthread, -lpthread)

SYNOPSIS
     #include <threads.h>

     int
     cnd_broadcast(cnd_t *cond);

     void
     cnd_destroy(cnd_t *cond);

     int
     cnd_init(cnd_t *cond);

     int
     cnd_signal(cnd_t *cond);

     int
     cnd_timedwait(cnd_t * __restrict cond, mtx_t * __restrict mtx,
         const struct timespec * __restrict ts);

     int
     cnd_wait(cnd_t *cond, mtx_t *mtx);

DESCRIPTION
     The cnd_broadcast() function unblocks all threads that are blocked on a
     condition variable cond at the time of the call.  If no thread is blocked
     on the cond condition variable at the time of the call, the function does
     nothing and returns success.

     The cnd_destroy() function destroys the cond condition variable.

     The cnd_init() function initializes a new cond variable.

     The cnd_signal() function unblock one thread that currently waits on the
     cond variable.  If there are no threads blocked, cnd_signal() does
     nothing and returns success.

     The cnd_timedwait() function atomically unlocks the mutex mtx and blocks
     on the condition variable cond until a thread is signalled by a call to
     cnd_signal() or cnd_broadcast() or timeout ts has been reached.  The ts
     parameter is specified as TIME_UTC based calendar time.  If the mutex is
     not locked by the calling thread then behavior is undefined.

     The cnd_wait() function atomically unlocks the mutex mtx and tries to
     block on the conditional variable cond until a thread is signalled by a
     call to cnd_signal() or cnd_broadcast().  The mtx mutex is locked again
     before the function returns.  If the mutex is not locked by the calling
     thread then behavior is undefined.

RETURN VALUES
     The cnd_broadcast() function returns thrd_success on success or
     thrd_error on failure.

     The cnd_destroy() function returns no value.

     The cnd_init() function returns thrd_success on success or thrd_error on
     failure.

     The cnd_signal() function returns thrd_success on success or thrd_error
     on failure.

     The cnd_timedwait() function returns thrd_success on success, otherwise
     thrd_timedout to indicate that system time has reached or exceeded the
     time specified in ts, or thrd_error on failure.

     The cnd_wait() function returns thrd_success on success or thrd_error on
     failure.

SEE ALSO
     pthread_cond(3), threads(3)

STANDARDS
     The cnd interface conforms to ISO/IEC 9899:2011 ("ISO C11").

HISTORY
     This interface first appeared in NetBSD 9.

AUTHORS
     Kamil Rytarowski <kamil@NetBSD.org>

NetBSD 10.99                   October 16, 2016                   NetBSD 10.99