moonpool/picos_std/Picos_std_sync/Latch/index.html
2025-04-15 14:16:12 +00:00

4 lines
5.6 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Latch (picos_std.Picos_std_sync.Latch)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.0.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> &#x00BB; <a href="../../index.html">picos_std</a> &#x00BB; <a href="../index.html">Picos_std_sync</a> &#x00BB; Latch</nav><header class="odoc-preamble"><h1>Module <code><span>Picos_std_sync.Latch</span></code></h1><p>A dynamic single-use countdown latch.</p><p>Latches are typically used for determining when a finite set of parallel computations is done. If the size of the set is known a priori, then the latch can be initialized with the size as initial count and then each computation just <a href="#val-decr" title="decr">decrements</a> the latch.</p><p>If the size is unknown, i.e. it is determined dynamically, then a latch is initialized with a count of one, the a priori known computations are started and then the latch is <a href="#val-decr" title="decr">decremented</a>. When a computation is stsrted, the latch is <a href="#val-try_incr" title="try_incr">incremented</a>, and then <a href="#val-decr" title="decr">decremented</a> once the computation has finished.</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>Represents a dynamic countdown latch.</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><span class="optlabel">?padded</span>:bool <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>create initial</code> creates a new countdown latch with the specified <code>initial</code> count.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>in case the specified <code>initial</code> count is negative.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_decr"><a href="#val-try_decr" class="anchor"></a><code><span><span class="keyword">val</span> try_decr : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>try_decr latch</code> attempts to decrement the count of the latch and returns <code>true</code> in case the count of the latch was greater than zero and <code>false</code> in case the count already was zero.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-decr"><a href="#val-decr" class="anchor"></a><code><span><span class="keyword">val</span> decr : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>decr latch</code> is equivalent to:</p><pre class="language-ocaml"><code> if not (try_decr latch) then
invalid_arg &quot;zero count&quot;</code></pre><p> This operation is not cancelable.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>in case the count of the latch is zero.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_incr"><a href="#val-try_incr" class="anchor"></a><code><span><span class="keyword">val</span> try_incr : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>try_incr latch</code> attempts to increment the count of the latch and returns <code>true</code> on success and <code>false</code> on failure, which means that the latch has already reached zero.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-incr"><a href="#val-incr" class="anchor"></a><code><span><span class="keyword">val</span> incr : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>incr latch</code> is equivalent to:</p><pre class="language-ocaml"><code> if not (try_incr latch) then
invalid_arg &quot;zero count&quot;</code></pre><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <code>Invalid_argument</code> <p>in case the count of the latch is zero.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-await"><a href="#val-await" class="anchor"></a><code><span><span class="keyword">val</span> await : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>await latch</code> returns after the count of the latch has reached zero.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-await_evt"><a href="#val-await_evt" class="anchor"></a><code><span><span class="keyword">val</span> await_evt : <span><a href="#type-t">t</a> <span class="arrow">&#45;&gt;</span></span> <span>unit <a href="../../Picos_std_event/Event/index.html#type-t">Picos_std_event.Event.t</a></span></span></code></div><div class="spec-doc"><p><code>await_evt latch</code> returns an event that can be committed to once the count of the latch has reached zero.</p></div></div></div></body></html>