Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
cnd_ |
Signal to all threads on a condition variable | ? | (·) | <threads.h> |
C11 | ||||||
cnd_ |
Destroy a condition variable | ? | (·) | <threads.h> |
C11 | ||||||
cnd_ |
Initialize a condition variable | ? | (·) | <threads.h> |
C11 | ||||||
cnd_ |
Signal to a thread on a condition variable | ? | (·) | <threads.h> |
C11 | ||||||
cnd_t |
Condition-variable type | ? | T | <threads.h> |
C11 | ||||||
cnd_ |
Wait on a condition variable for a limited time | ? | (·) | <threads.h> |
C11 | ||||||
cnd_ |
Wait on a condition variable | ? | (·) | <threads.h> |
C11 |
Names matching ^cnd_[a-z]
might be added to <threads.h>
.
A condition variable is a construct that allows
threads to synchronize
with each other. <threads.h>
defines a type cnd_t
to represent a condition variable. Any number of threads can
wait on a condition variable, blocking until some
other thread signals the variable, which can
unblock one thread arbitrarily, or all threads.
#include<threads.h>
int cnd_init (cnd_t *cp); void cnd_destroy (cnd_t *cp);
A condition variable c
must be
initialized with cnd_
before being used by any other function. Resources allocated
for it by cnd_
should be released with cnd_
.
cnd_
returns thrd_
on success,
thrd_
if there is
insufficient memory to initialize the variable, or
thrd_
on any other kind of
failure.
#include<threads.h>
int cnd_wait (cnd_t *cp, mtx_t *mp); int cnd_timedwait (cnd_t *cp, mtx_t *mp, const struct timespec *tp);
While a thread has the lock on mutex m
, it can wait indefinitely for a signal on
condition variable c
by calling
cnd_
, or it can wait for a limited time
t
with
cnd_
. The
mutex is unlocked just before the thread starts waiting, and
every thread unblocked by a signal will first attempt to
claim the lock before its call to cnd_
or
cnd_
returns.
These functions return thrd_
when successfully
signalled, and thrd_
if it was not possible
to wait.
cnd_
returns thrd_
if the wait timed out
before the thread was signalled.
#include<threads.h>
int cnd_signal (cnd_t *cp); int cnd_broadcast (cnd_t *cp);
These functions signal threads waiting on the condition
variable *cp
.
cnd_
chooses one thread arbitrarily
and signals it.
cnd_
signals all threads waiting
on the variable. These functions return thrd_
on success and
thrd_
on error.