mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
2 lines
4.3 KiB
HTML
2 lines
4.3 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Lwt_mutex (lwt.Lwt_mutex)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> – <a href="../../index.html">Index</a> » <a href="../index.html">lwt</a> » Lwt_mutex</nav><header class="odoc-preamble"><h1>Module <code><span>Lwt_mutex</span></code></h1><p>Cooperative locks for mutual exclusion</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span></code></div><div class="spec-doc"><p>Type of Lwt mutexes</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-create"><a href="#val-create" class="anchor"></a><code><span><span class="keyword">val</span> create : <span>unit <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>create ()</code> creates a new mutex, which is initially unlocked</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-lock"><a href="#val-lock" class="anchor"></a><code><span><span class="keyword">val</span> lock : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>unit <a href="../Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p><code>lock mutex</code> lockcs the mutex, that is:</p><ul><li>if the mutex is unlocked, then it is marked as locked and <a href="#val-lock"><code>lock</code></a> returns immediately</li></ul><ul><li>if it is locked, then <a href="#val-lock"><code>lock</code></a> waits for all threads waiting on the mutex to terminate, then it resumes when the last one unlocks the mutex</li></ul><p>Note: threads are woken up in the same order they try to lock the mutex</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-unlock"><a href="#val-unlock" class="anchor"></a><code><span><span class="keyword">val</span> unlock : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>unlock mutex</code> unlock the mutex if no threads is waiting on it. Otherwise it will eventually removes the first one and resumes it.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_locked"><a href="#val-is_locked" class="anchor"></a><code><span><span class="keyword">val</span> is_locked : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>locked mutex</code> returns whether <code>mutex</code> is currently locked</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_empty"><a href="#val-is_empty" class="anchor"></a><code><span><span class="keyword">val</span> is_empty : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>is_empty mutex</code> returns <code>true</code> if they are no thread waiting on the mutex, and <code>false</code> otherwise</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-with_lock"><a href="#val-with_lock" class="anchor"></a><code><span><span class="keyword">val</span> with_lock : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><span>(<span>unit <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="../Lwt/index.html#type-t">Lwt.t</a></span>)</span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="../Lwt/index.html#type-t">Lwt.t</a></span></span></code></div><div class="spec-doc"><p><code>with_lock lock f</code> is used to lock a mutex within a block scope. The function <code>f ()</code> is called with the mutex locked, and its result is returned from the call to <code>with_lock</code>. If an exception is raised from f, the mutex is also unlocked before the scope of <code>with_lock</code> is exited.</p></div></div></div></body></html>
|