mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-17 08:06:43 -05:00
2 lines
No EOL
4.1 KiB
HTML
2 lines
No EOL
4.1 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Counting (ocaml.Stdlib.Semaphore.Counting)</title><link rel="stylesheet" href="../../../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><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">ocaml</a> » <a href="../../index.html">Stdlib</a> » <a href="../index.html">Semaphore</a> » Counting</nav><header class="odoc-preamble"><h1>Module <code><span>Semaphore.Counting</span></code></h1></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>The type of counting semaphores.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-make"><a href="#val-make" class="anchor"></a><code><span><span class="keyword">val</span> make : <span>int <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>make n</code> returns a new counting semaphore, with initial value <code>n</code>. The initial value <code>n</code> must be nonnegative.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Invalid_argument</span> <p>if <code>n < 0</code></p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-release"><a href="#val-release" class="anchor"></a><code><span><span class="keyword">val</span> release : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>release s</code> increments the value of semaphore <code>s</code>. If other threads are waiting on <code>s</code>, one of them is restarted. If the current value of <code>s</code> is equal to <code>max_int</code>, the value of the semaphore is unchanged and a <code>Sys_error</code> exception is raised to signal overflow.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Sys_error</span> <p>if the value of the semaphore would overflow <code>max_int</code></p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-acquire"><a href="#val-acquire" class="anchor"></a><code><span><span class="keyword">val</span> acquire : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>acquire s</code> blocks the calling thread until the value of semaphore <code>s</code> is not zero, then atomically decrements the value of <code>s</code> and returns.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_acquire"><a href="#val-try_acquire" class="anchor"></a><code><span><span class="keyword">val</span> try_acquire : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>try_acquire s</code> immediately returns <code>false</code> if the value of semaphore <code>s</code> is zero. Otherwise, the value of <code>s</code> is atomically decremented and <code>try_acquire s</code> returns <code>true</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_value"><a href="#val-get_value" class="anchor"></a><code><span><span class="keyword">val</span> get_value : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p><code>get_value s</code> returns the current value of semaphore <code>s</code>. The current value can be modified at any time by concurrent <a href="#val-release"><code>release</code></a> and <a href="#val-acquire"><code>acquire</code></a> operations. Hence, the <code>get_value</code> operation is racy, and its result should only be used for debugging or informational messages.</p></div></div></div></body></html> |