2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright 2016 Joyent, Inc.
25 .Nd C11 condition variable functions
46 .Fa "cnd_t *restrict cnd"
47 .Fa "mtx_t *restrict mtx"
48 .Fa "const struct timespec *abstime"
52 .Fa "cnd_t *restrict cnd"
53 .Fa "mtx_t *restrict mtx"
58 family of functions implement condition variables which allow threads
59 within a process to wait until a condition occurs and be signaled when
61 These functions behave similar to both the POSIX threads and illumos threads;
62 however, they have slightly different call signatures and return values.
63 For more information, see
65 Importantly, they do not allow for inter-process synchronization.
66 .Ss Creating and Destroy Condition Variables
69 initializes the condition variable referred to by
71 The condition variable is suitable for intra-process use.
72 Initializing an already initialized condition variable results in undefined
77 destroys an initialized condition variable at which point it is illegal
78 to use it, though it may be initialized again.
82 can be used to wait on a condition variable.
83 A thread that waits on a condition variable blocks until another thread signals
84 that the condition has changed, generally after making the condition that was
89 atomically release the mutex pointed to by
91 and blocks on the condition variable
93 When the thread returns, it will once again be holding
95 and must check the current state of the condition.
96 There is no guarantee that another thread has not gotten in and changed the
97 value before being woken.
98 In addition, a thread blocking on a condition variable, may be woken spuriously,
99 such as when a signal is received or
105 allows a thread to block in a similar fashion to
107 except that when the absolute time specified in seconds since the epoch
110 in UTC, expires, then the thread will be woken up.
111 The timeout is specified in
113 .Ss Conditional Signaling
118 functions can be used to signal threads waiting on the condition variable
120 that they should be woken up and check the variable again.
123 function will only wake a single thread that is blocked on the
128 will wake up every thread waiting on the condition variable
131 A thread calling either
135 is not required to hold any of the mutexes that are associated with the
138 If there are no threads currently blocked in the condition variable
140 then neither function has an effect.
142 Upon successful completion, the
146 If insufficient memory was available, then
148 is returned; otherwise, if any other error occurred,
152 Upon successful completion, the
159 Otherwise, they return
161 to indicate that an error occurred and they were unable to complete.
163 Upon successful completion, the
169 expires without being signaled, it instead returns
173 is returned to indicate an error.
174 .Sh INTERFACE STABILITY
179 .Xr cond_braodcast 3C ,
180 .Xr cond_destroy 3C ,
183 .Xr cond_timedwait 3C ,