mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
2 lines
No EOL
3.3 KiB
HTML
2 lines
No EOL
3.3 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>CCSemaphore (containers-thread.CCSemaphore)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> – <a href="../index.html">containers-thread</a> » CCSemaphore</nav><h1>Module <code>CCSemaphore</code></h1><h2 id="semaphores"><a href="#semaphores" class="anchor"></a>Semaphores</h2><dl><dt>since</dt><dd>0.13</dd></dl></header><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> t</code></dt><dd><p>A semaphore</p></dd></dl><dl><dt class="spec value" id="val-create"><a href="#val-create" class="anchor"></a><code><span class="keyword">val</span> create : int <span>-></span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>create n</code> creates a semaphore with initial value <code>n</code>.</p><dl><dt>raises Invalid_argument</dt><dd><p>if <code>n <= 0</code>.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-get"><a href="#val-get" class="anchor"></a><code><span class="keyword">val</span> get : <a href="index.html#type-t">t</a> <span>-></span> int</code></dt><dd><p>Current value.</p></dd></dl><dl><dt class="spec value" id="val-acquire"><a href="#val-acquire" class="anchor"></a><code><span class="keyword">val</span> acquire : int <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p><code>acquire n s</code> blocks until <code>get s >= n</code>, then atomically sets <code>s := !s - n</code>.</p></dd></dl><dl><dt class="spec value" id="val-release"><a href="#val-release" class="anchor"></a><code><span class="keyword">val</span> release : int <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> unit</code></dt><dd><p><code>release n s</code> atomically sets <code>s := !s + n</code>.</p></dd></dl><dl><dt class="spec value" id="val-with_acquire"><a href="#val-with_acquire" class="anchor"></a><code><span class="keyword">val</span> with_acquire : n:int <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> f:(unit <span>-></span> <span class="type-var">'a</span>) <span>-></span> <span class="type-var">'a</span></code></dt><dd><p><code>with_acquire ~n s ~f</code> first acquires <code>s</code> with <code>n</code> units, calls <code>f ()</code>, and then releases <code>s</code> with <code>n</code> units. Safely release the semaphore even if <code>f ()</code> fails.</p></dd></dl><dl><dt class="spec value" id="val-wait_until_at_least"><a href="#val-wait_until_at_least" class="anchor"></a><code><span class="keyword">val</span> wait_until_at_least : n:int <span>-></span> <a href="index.html#type-t">t</a> <span>-></span> f:(unit <span>-></span> <span class="type-var">'a</span>) <span>-></span> <span class="type-var">'a</span></code></dt><dd><p><code>wait_until_at_least ~n s ~f</code> waits until <code>get s >= n</code>, then calls <code>f ()</code> and returns its result. Doesn't modify the semaphore.</p></dd></dl></div></body></html> |