-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Counter (less-power.Thread_counter.Counter)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../odoc.support/odoc.css"/><meta name="generator" content="odoc 2.4.2"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../odoc.support/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">less-power</a> » <a href="../index.html">Thread_counter</a> » Counter</nav><header class="odoc-preamble"><h1>Module <code><span>Thread_counter.Counter</span></code></h1></header><nav class="odoc-toc"><ul><li><a href="#high-level-group-operations">High-level group operations</a></li></ul></nav><div class="odoc-content"><div class="odoc-spec"><div class="spec value anchored" id="val-lock_if"><a href="#val-lock_if" class="anchor"></a><code><span><span class="keyword">val</span> lock_if : <span>bool <span class="arrow">-></span></span> <span><span class="xref-unresolved">Stdlib</span>.Mutex.t <span class="arrow">-></span></span> <span><span>(unit, <span class="type-var">'a</span>, <span class="type-var">'a</span>)</span> <a href="../../Common/Ctx_util/index.html#type-t">Common.Ctx_util.t</a></span></span></code></div></div><p>Note: we enforce that spawned threads don't raise uncaught exceptions, which in theory changes the semantics of threads. The value of being able to report stray exceptions outweighs the slim chance anyone would rely on being able to ignore exceptions in threads.</p><div class="odoc-spec"><div class="spec type anchored" id="type-finished"><a href="#type-finished" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a finished</span></span><span> = </span></code><ol><li id="type-finished.Return" class="def variant constructor anchored"><a href="#type-finished.Return" class="anchor"></a><code><span>| </span><span><span class="constructor">Return</span> <span class="keyword">of</span> <span class="type-var">'a</span></span></code></li><li id="type-finished.Uncaught" class="def variant constructor anchored"><a href="#type-finished.Uncaught" class="anchor"></a><code><span>| </span><span><span class="constructor">Uncaught</span> <span class="keyword">of</span> <a href="../../Common/Util/index.html#type-exn_info">Common.Util.exn_info</a></span></code></li><li id="type-finished.Overflow" class="def variant constructor anchored"><a href="#type-finished.Overflow" class="anchor"></a><code><span>| </span><span><span class="constructor">Overflow</span> <span class="keyword">of</span> int</span></code></li></ol></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-state"><a href="#type-state" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a state</span></span><span> = </span></code><ol><li id="type-state.Running" class="def variant constructor anchored"><a href="#type-state.Running" class="anchor"></a><code><span>| </span><span><span class="constructor">Running</span></span></code></li><li id="type-state.Finished" class="def variant constructor anchored"><a href="#type-state.Finished" class="anchor"></a><code><span>| </span><span><span class="constructor">Finished</span> <span class="keyword">of</span> <span><span class="type-var">'a</span> <a href="#type-finished">finished</a></span></span></code></li></ol></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-group"><a href="#type-group" class="anchor"></a><code><span><span class="keyword">type</span> <span>'a group</span></span><span> = </span><span>{</span></code><ol><li id="type-group.state" class="def record field anchored"><a href="#type-group.state" class="anchor"></a><code><span><span class="keyword">mutable</span> state : <span><span class="type-var">'a</span> <a href="#type-state">state</a></span>;</span></code></li><li id="type-group.finished" class="def record field anchored"><a href="#type-group.finished" class="anchor"></a><code><span>finished : <span class="xref-unresolved">Stdlib</span>.Condition.t;</span></code></li><li id="type-group.thread_count" class="def record field anchored"><a href="#type-group.thread_count" class="anchor"></a><code><span><span class="keyword">mutable</span> thread_count : int;</span></code></li><li id="type-group.thread_limit" class="def record field anchored"><a href="#type-group.thread_limit" class="anchor"></a><code><span>thread_limit : <span>int option</span>;</span></code></li><li id="type-group.owner" class="def record field anchored"><a href="#type-group.owner" class="anchor"></a><code><span>owner : <a href="#type-t">t</a>;</span></code></li></ol><code><span>}</span></code></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-g"><a href="#type-g" class="anchor"></a><code><span><span class="keyword">and</span> g</span><span> = </span></code><ol><li id="type-g.G" class="def variant constructor anchored"><a href="#type-g.G" class="anchor"></a><code><span>| </span><span><span class="constructor">G</span> : <span><span class="type-var">'a</span> <a href="#type-group">group</a></span> <span class="arrow">-></span> <a href="#type-g">g</a></span></code></li></ol></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">and</span> t</span><span> = </span><span>{</span></code><ol><li id="type-t.mut" class="def record field anchored"><a href="#type-t.mut" class="anchor"></a><code><span>mut : <span class="xref-unresolved">Stdlib</span>.Mutex.t;</span></code></li><li id="type-t.groups" class="def record field anchored"><a href="#type-t.groups" class="anchor"></a><code><span>groups : <span><a href="#type-g">g</a> <a href="../ThreadH/index.html#type-t">ThreadH.t</a></span>;</span></code></li></ol><code><span>}</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-finish"><a href="#val-finish" class="anchor"></a><code><span><span class="keyword">val</span> finish : <span><span class="optlabel">?lock</span>:bool <span class="arrow">-></span></span> <span><span><span class="type-var">'a</span> <a href="#type-group">group</a></span> <span class="arrow">-></span></span> <span><span><span class="type-var">'b</span> <a href="#type-finished">finished</a></span> <span class="arrow">-></span></span> unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_finish"><a href="#val-try_finish" class="anchor"></a><code><span><span class="keyword">val</span> try_finish : <span><span><span class="type-var">'a</span> <a href="#type-group">group</a></span> <span class="arrow">-></span></span> <span><span><span class="type-var">'a</span> <a href="#type-finished">finished</a></span> <span class="arrow">-></span></span> unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-try_return"><a href="#val-try_return" class="anchor"></a><code><span><span class="keyword">val</span> try_return : <span><span><span class="type-var">'a</span> <a href="#type-group">group</a></span> <span class="arrow">-></span></span> <span><span class="type-var">'b</span> <span class="arrow">-></span></span> unit</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-spawn_thread"><a href="#val-spawn_thread" class="anchor"></a><code><span><span class="keyword">val</span> spawn_thread : | ||
<span><span class="optlabel">?lock</span>:bool <span class="arrow">-></span></span> | ||
<span><span class="optlabel">?group</span>:<span><span class="type-var">'a</span> <a href="#type-group">group</a></span> <span class="arrow">-></span></span> | ||
<span><a href="#type-t">t</a> <span class="arrow">-></span></span> | ||
<span><span>(<span><span class="type-var">'b</span> <span class="arrow">-></span></span> unit)</span> <span class="arrow">-></span></span> | ||
<span><span class="type-var">'c</span> <span class="arrow">-></span></span> | ||
<span class="xref-unresolved">Thread</span>.t</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-create_counter"><a href="#val-create_counter" class="anchor"></a><code><span><span class="keyword">val</span> create_counter : <span>unit <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-create_group"><a href="#val-create_group" class="anchor"></a><code><span><span class="keyword">val</span> create_group : <span><span class="optlabel">?thread_limit</span>:int <span class="arrow">-></span></span> <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="#type-group">group</a></span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_thread_count"><a href="#val-get_thread_count" class="anchor"></a><code><span><span class="keyword">val</span> get_thread_count : <span><span><span class="type-var">'a</span> <a href="#type-group">group</a></span> <span class="arrow">-></span></span> int</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-join_group"><a href="#val-join_group" class="anchor"></a><code><span><span class="keyword">val</span> join_group : | ||
<span><span class="label">leftover_thread_limit</span>:int <span class="arrow">-></span></span> | ||
<span><span class="label">timeout</span>:<span class="xref-unresolved">Mtime</span>.span <span class="arrow">-></span></span> | ||
<span><span><span class="type-var">'a</span> <a href="#type-group">group</a></span> <span class="arrow">-></span></span> | ||
int</span></code></div><div class="spec-doc"><p>Wait for threads in a group to complete. Group must be finished first.</p></div></div><h2 id="high-level-group-operations"><a href="#high-level-group-operations" class="anchor"></a>High-level group operations</h2><div class="odoc-spec"><div class="spec type anchored" id="type-thread_group_err"><a href="#type-thread_group_err" class="anchor"></a><code><span><span class="keyword">type</span> thread_group_err</span><span> = </span></code><ol><li id="type-thread_group_err.ThreadLimitReached" class="def variant constructor anchored"><a href="#type-thread_group_err.ThreadLimitReached" class="anchor"></a><code><span>| </span><span><span class="constructor">ThreadLimitReached</span> <span class="keyword">of</span> int</span></code></li><li id="type-thread_group_err.ThreadsLeftOver" class="def variant constructor anchored"><a href="#type-thread_group_err.ThreadsLeftOver" class="anchor"></a><code><span>| </span><span><span class="constructor">ThreadsLeftOver</span> <span class="keyword">of</span> </span><span>{</span></code><ol><li id="type-thread_group_err.left_over" class="def record field anchored"><a href="#type-thread_group_err.left_over" class="anchor"></a><code><span>left_over : int;</span></code></li><li id="type-thread_group_err.limit" class="def record field anchored"><a href="#type-thread_group_err.limit" class="anchor"></a><code><span>limit : int;</span></code></li></ol><code><span>}</span></code></li><li id="type-thread_group_err.ExceptionRaised" class="def variant constructor anchored"><a href="#type-thread_group_err.ExceptionRaised" class="anchor"></a><code><span>| </span><span><span class="constructor">ExceptionRaised</span> <span class="keyword">of</span> </span><span>{</span></code><ol><li id="type-thread_group_err.main" class="def record field anchored"><a href="#type-thread_group_err.main" class="anchor"></a><code><span>main : bool;</span></code></li><li id="type-thread_group_err.exn_info" class="def record field anchored"><a href="#type-thread_group_err.exn_info" class="anchor"></a><code><span>exn_info : <a href="../../Common/Util/index.html#type-exn_info">Common.Util.exn_info</a>;</span></code></li></ol><code><span>}</span></code></li></ol></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-spawn_thread_group"><a href="#val-spawn_thread_group" class="anchor"></a><code><span><span class="keyword">val</span> spawn_thread_group : | ||
<span><span class="optlabel">?thread_limit</span>:int <span class="arrow">-></span></span> | ||
<span><a href="#type-t">t</a> <span class="arrow">-></span></span> | ||
<span><span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span> | ||
<span><span class="type-var">'c</span> <span class="arrow">-></span></span> | ||
<span><span><span>(<span class="type-var">'b</span>, <a href="../../Common/Util/index.html#type-exn_info">Common.Util.exn_info</a>)</span> <span class="xref-unresolved">Stdlib</span>.result</span> <a href="#type-group">group</a></span></span></code></div><div class="spec-doc"><p>Create a group that runs the given function, then sets the return value as the return value of the group.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-collect_thread_group"><a href="#val-collect_thread_group" class="anchor"></a><code><span><span class="keyword">val</span> collect_thread_group : | ||
<span><span class="optlabel">?leftover_limit</span>:<span>(int * <span class="xref-unresolved">Mtime</span>.span)</span> <span class="arrow">-></span></span> | ||
<span><span><span class="type-var">'a</span> <a href="#type-group">group</a></span> <span class="arrow">-></span></span> | ||
<span><span class="type-var">'b</span> <a href="#type-finished">finished</a></span> * int</span></code></div><div class="spec-doc"><p>Wait for a group to finish then join its threads (<a href="#val-join_group"><code>join_group</code></a>).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-check_thread_group_result"><a href="#val-check_thread_group_result" class="anchor"></a><code><span><span class="keyword">val</span> check_thread_group_result : | ||
<span><span class="optlabel">?leftover_limit</span>:<span>(int * <span class="xref-unresolved">Mtime</span>.span)</span> <span class="arrow">-></span></span> | ||
<span><span><span><span>(<span class="type-var">'a</span>, <a href="../../Common/Util/index.html#type-exn_info">Common.Util.exn_info</a>)</span> <span class="xref-unresolved">Stdlib</span>.result</span> <a href="#type-finished">finished</a></span> <span class="arrow">-></span></span> | ||
<span>int <span class="arrow">-></span></span> | ||
<span><span>(<span class="type-var">'b</span>, <span><a href="#type-thread_group_err">thread_group_err</a> list</span>)</span> <span class="xref-unresolved">Stdlib</span>.result</span></span></code></div><div class="spec-doc"><p>Check the return value of <a href="#val-collect_thread_group"><code>collect_thread_group</code></a></p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-run_in_thread_group"><a href="#val-run_in_thread_group" class="anchor"></a><code><span><span class="keyword">val</span> run_in_thread_group : | ||
<span><span class="optlabel">?thread_limit</span>:int <span class="arrow">-></span></span> | ||
<span><span class="optlabel">?leftover_limit</span>:<span>(int * <span class="xref-unresolved">Mtime</span>.span)</span> <span class="arrow">-></span></span> | ||
<span><a href="#type-t">t</a> <span class="arrow">-></span></span> | ||
<span><span>(<span><span class="type-var">'a</span> <span class="arrow">-></span></span> <span class="type-var">'b</span>)</span> <span class="arrow">-></span></span> | ||
<span><span class="type-var">'c</span> <span class="arrow">-></span></span> | ||
<span><span>(<span class="type-var">'d</span>, <span><a href="#type-thread_group_err">thread_group_err</a> list</span>)</span> <span class="xref-unresolved">Stdlib</span>.result</span></span></code></div><div class="spec-doc"><p>Combines <a href="#val-spawn_thread_group"><code>spawn_thread_group</code></a>, <a href="#val-collect_thread_group"><code>collect_thread_group</code></a>, and <a href="#val-check_thread_group_result"><code>check_thread_group_result</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-string_of_thread_group_err"><a href="#val-string_of_thread_group_err" class="anchor"></a><code><span><span class="keyword">val</span> string_of_thread_group_err : <span><a href="#type-thread_group_err">thread_group_err</a> <span class="arrow">-></span></span> string</span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-string_of_thread_group_errs"><a href="#val-string_of_thread_group_errs" class="anchor"></a><code><span><span class="keyword">val</span> string_of_thread_group_errs : <span><span><a href="#type-thread_group_err">thread_group_err</a> list</span> <span class="arrow">-></span></span> string</span></code></div></div><div class="odoc-spec"><div class="spec exception anchored" id="exception-ThreadGroupErrs"><a href="#exception-ThreadGroupErrs" class="anchor"></a><code><span><span class="keyword">exception</span> </span><span><span class="exception">ThreadGroupErrs</span> <span class="keyword">of</span> <span><a href="#type-thread_group_err">thread_group_err</a> list</span></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-thread_group_result_to_exn"><a href="#val-thread_group_result_to_exn" class="anchor"></a><code><span><span class="keyword">val</span> thread_group_result_to_exn : | ||
<span><span><span>(<span class="type-var">'a</span>, <span><a href="#type-thread_group_err">thread_group_err</a> list</span>)</span> <span class="xref-unresolved">Stdlib</span>.result</span> <span class="arrow">-></span></span> | ||
<span class="type-var">'b</span></span></code></div></div></div></body></html> |
Oops, something went wrong.