| 1 |
@node Condition variables |
| 2 |
@subsection Condition variables |
| 3 |
|
| 4 |
Condition variables are used to wait for a particular condition becoming |
| 5 |
true (e.g new client connects to the server). |
| 6 |
|
| 7 |
@node Condition variables dictionary |
| 8 |
@subsection Condition variables dictionary |
| 9 |
|
| 10 |
|
| 11 |
@cppdef mp_make_condition_variable |
| 12 |
@lspdef mp:make-condition-variable |
| 13 |
|
| 14 |
@deftypefun cl_object mp_make_condition_variable () |
| 15 |
@end deftypefun |
| 16 |
|
| 17 |
@defun mp:make-condition-variable |
| 18 |
Creates a condition variable. |
| 19 |
@end defun |
| 20 |
|
| 21 |
|
| 22 |
@cppdef mp_condition_variable_wait |
| 23 |
@lspdef mp:condition-variable-wait |
| 24 |
|
| 25 |
@deftypefun cl_object mp_condition_variable_wait (cl_object cv, cl_object lock) |
| 26 |
@end deftypefun |
| 27 |
|
| 28 |
@defun mp:condition-variable-wait cv lock |
| 29 |
Release @var{lock} and suspend thread until |
| 30 |
@coderef{mp:condition-variable-signal} or |
| 31 |
@coderef{mp:condition-variable-broadcast} is called on @var{cv}. When |
| 32 |
thread resumes re-aquire @var{lock}. Always returns @code{t}. May signal |
| 33 |
an error if @var{lock} is not owned by the current thread. |
| 34 |
|
| 35 |
@strong{Note:} In some circumstances, the thread may wake up even if no |
| 36 |
call to @coderef{mp:condition-variable-signal} or |
| 37 |
@coderef{mp:condition-variable-broadcast} has happened. It is |
| 38 |
recommended to check for the condition that triggered the wait in a loop |
| 39 |
around any @code{mp:condition-variable-wait} call. |
| 40 |
|
| 41 |
@strong{Note:} While the condition variable is blocked waiting for a |
| 42 |
signal or broadcast event, calling @code{mp:condition-variable-wait} |
| 43 |
from further threads must be done using the same mutex as that used by |
| 44 |
the threads that are already waiting on this condition variable. The |
| 45 |
behaviour is undefined if this constraint is violated. |
| 46 |
@end defun |
| 47 |
|
| 48 |
|
| 49 |
@cppdef mp_condition_variable_timedwait |
| 50 |
@lspdef mp:condition-variable-timedwait |
| 51 |
|
| 52 |
@deftypefun cl_object mp_condition_variable_timedwait (cl_object cv, cl_object lock, cl_object seconds) |
| 53 |
@end deftypefun |
| 54 |
|
| 55 |
@defun mp:condition-variable-timedwait cv lock seconds |
| 56 |
@coderef{mp:condition-variable-wait} which timeouts after @var{seconds} |
| 57 |
seconds. Returns @code{nil} on timeout and @code{t} otherwise. May |
| 58 |
signal an error if @var{lock} is not owned by the current thread. |
| 59 |
@end defun |
| 60 |
|
| 61 |
|
| 62 |
@cppdef mp_condition_variable_signal |
| 63 |
@lspdef mp:condition-variable-signal |
| 64 |
|
| 65 |
@deftypefun cl_object mp_condition_variable_signal (cl_object cv) |
| 66 |
@end deftypefun |
| 67 |
|
| 68 |
@defun mp:condition-variable-signal cv |
| 69 |
Wake up at least one of the waiters of @var{cv}. Usually, this will wake |
| 70 |
up only a single thread, but it may also wake up multiple threads. |
| 71 |
Always returns @code{t}. |
| 72 |
|
| 73 |
See @coderef{mp:condition-variable-wait}. |
| 74 |
@end defun |
| 75 |
|
| 76 |
|
| 77 |
@cppdef mp_condition_variable-broadcast |
| 78 |
@lspdef mp:condition-variable-broadcast |
| 79 |
|
| 80 |
@deftypefun cl_object mp_condition_variable_broadcast (cl_object cv) |
| 81 |
@end deftypefun |
| 82 |
|
| 83 |
@defun mp:condition-variable-broadcast cv |
| 84 |
Wake up all waiters of @var{cv}. Always returns @code{t}. |
| 85 |
|
| 86 |
See @coderef{mp:condition-variable-wait}. |
| 87 |
@end defun |