diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/condition-variables.html | |
new repository
Diffstat (limited to 'devdocs/elisp/condition-variables.html')
| -rw-r--r-- | devdocs/elisp/condition-variables.html | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/devdocs/elisp/condition-variables.html b/devdocs/elisp/condition-variables.html new file mode 100644 index 00000000..4cd66d97 --- /dev/null +++ b/devdocs/elisp/condition-variables.html @@ -0,0 +1,30 @@ + <h3 class="section">Condition Variables</h3> <p>A <em>condition variable</em> is a way for a thread to block until some event occurs. A thread can wait on a condition variable, to be woken up when some other thread notifies the condition. </p> <p>A condition variable is associated with a mutex and, conceptually, with some condition. For proper operation, the mutex must be acquired, and then a waiting thread must loop, testing the condition and waiting on the condition variable. For example: </p> <div class="example"> <pre class="example">(with-mutex mutex + (while (not global-variable) + (condition-wait cond-var))) +</pre> +</div> <p>The mutex ensures atomicity, and the loop is for robustness—there may be spurious notifications. </p> <p>Similarly, the mutex must be held before notifying the condition. The typical, and best, approach is to acquire the mutex, make the changes associated with this condition, and then notify it: </p> <div class="example"> <pre class="example">(with-mutex mutex + (setq global-variable (some-computation)) + (condition-notify cond-var)) +</pre> +</div> <dl> <dt id="make-condition-variable">Function: <strong>make-condition-variable</strong> <em>mutex &optional name</em> +</dt> <dd><p>Make a new condition variable associated with <var>mutex</var>. If <var>name</var> is specified, it is a name given to the condition variable. It must be a string. The name is for debugging purposes only; it has no meaning to Emacs. </p></dd> +</dl> <dl> <dt id="condition-variable-p">Function: <strong>condition-variable-p</strong> <em>object</em> +</dt> <dd><p>This function returns <code>t</code> if <var>object</var> represents a condition variable, <code>nil</code> otherwise. </p></dd> +</dl> <dl> <dt id="condition-wait">Function: <strong>condition-wait</strong> <em>cond</em> +</dt> <dd> +<p>Wait for another thread to notify <var>cond</var>, a condition variable. This function will block until the condition is notified, or until a signal is delivered to this thread using <code>thread-signal</code>. </p> <p>It is an error to call <code>condition-wait</code> without holding the condition’s associated mutex. </p> <p><code>condition-wait</code> releases the associated mutex while waiting. This allows other threads to acquire the mutex in order to notify the condition. </p> +</dd> +</dl> <dl> <dt id="condition-notify">Function: <strong>condition-notify</strong> <em>cond &optional all</em> +</dt> <dd> +<p>Notify <var>cond</var>. The mutex with <var>cond</var> must be held before calling this. Ordinarily a single waiting thread is woken by <code>condition-notify</code>; but if <var>all</var> is not <code>nil</code>, then all threads waiting on <var>cond</var> are notified. </p> <p><code>condition-notify</code> releases the associated mutex while waiting. This allows other threads to acquire the mutex in order to wait on the condition. </p> +</dd> +</dl> <dl> <dt id="condition-name">Function: <strong>condition-name</strong> <em>cond</em> +</dt> <dd><p>Return the name of <var>cond</var>, as passed to <code>make-condition-variable</code>. </p></dd> +</dl> <dl> <dt id="condition-mutex">Function: <strong>condition-mutex</strong> <em>cond</em> +</dt> <dd><p>Return the mutex associated with <var>cond</var>. Note that the associated mutex cannot be changed. </p></dd> +</dl><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Condition-Variables.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Condition-Variables.html</a> + </p> +</div> |
