mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-17 08:06:43 -05:00
5 lines
No EOL
7.5 KiB
HTML
5 lines
No EOL
7.5 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Domain (ocaml.Stdlib.Domain)</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> » Domain</nav><header class="odoc-preamble"><h1>Module <code><span>Stdlib.Domain</span></code></h1><ul class="at-tags"><li class="alert"><span class="at-tag">alert</span> unstable The Domain interface may change in incompatible ways in the future.</li></ul><p>Domains.</p><p>See 'Parallel programming' chapter in the manual.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 5.0</li></ul><ul class="at-tags"><li class="alert"><span class="at-tag">alert</span> unstable The Domain interface may change in incompatible ways in the future.</li></ul></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> <span>!'a t</span></span></code></div><div class="spec-doc"><p>A domain of type <code>'a t</code> runs independently, eventually producing a result of type 'a, or an exception</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-spawn"><a href="#val-spawn" class="anchor"></a><code><span><span class="keyword">val</span> spawn : <span><span>(<span>unit <span class="arrow">-></span></span> <span class="type-var">'a</span>)</span> <span class="arrow">-></span></span> <span><span class="type-var">'a</span> <a href="#type-t">t</a></span></span></code></div><div class="spec-doc"><p><code>spawn f</code> creates a new domain that runs in parallel with the current domain.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-join"><a href="#val-join" class="anchor"></a><code><span><span class="keyword">val</span> join : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>join d</code> blocks until domain <code>d</code> runs to completion. If <code>d</code> results in a value, then that is returned by <code>join d</code>. If <code>d</code> raises an uncaught exception, then that is re-raised by <code>join d</code>.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-id"><a href="#type-id" class="anchor"></a><code><span><span class="keyword">type</span> id</span><span> = <span class="keyword">private</span> int</span></code></div><div class="spec-doc"><p>Domains have unique integer identifiers</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_id"><a href="#val-get_id" class="anchor"></a><code><span><span class="keyword">val</span> get_id : <span><span><span class="type-var">'a</span> <a href="#type-t">t</a></span> <span class="arrow">-></span></span> <a href="#type-id">id</a></span></code></div><div class="spec-doc"><p><code>get_id d</code> returns the identifier of the domain <code>d</code></p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-self"><a href="#val-self" class="anchor"></a><code><span><span class="keyword">val</span> self : <span>unit <span class="arrow">-></span></span> <a href="#type-id">id</a></span></code></div><div class="spec-doc"><p><code>self ()</code> is the identifier of the currently running domain</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-before_first_spawn"><a href="#val-before_first_spawn" class="anchor"></a><code><span><span class="keyword">val</span> before_first_spawn : <span><span>(<span>unit <span class="arrow">-></span></span> unit)</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>before_first_spawn f</code> registers <code>f</code> to be called before the first domain is spawned by the program. The functions registered with <code>before_first_spawn</code> are called on the main (initial) domain. The functions registered with <code>before_first_spawn</code> are called in 'first in, first out' order: the oldest function added with <code>before_first_spawn</code> is called first.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Invalid_argument</span> <p>if the program has already spawned a domain.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-at_exit"><a href="#val-at_exit" class="anchor"></a><code><span><span class="keyword">val</span> at_exit : <span><span>(<span>unit <span class="arrow">-></span></span> unit)</span> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>at_exit f</code> registers <code>f</code> to be called when the current domain exits. Note that <code>at_exit</code> callbacks are domain-local and only apply to the calling domain. The registered functions are called in 'last in, first out' order: the function most recently added with <code>at_exit</code> is called first. An example:</p><pre class="language-ocaml"><code>let temp_file_key = Domain.DLS.new_key (fun _ ->
|
||
let tmp = snd (Filename.open_temp_file "" "") in
|
||
Domain.at_exit (fun () -> close_out_noerr tmp);
|
||
tmp)</code></pre><p>The snippet above creates a key that when retrieved for the first time will open a temporary file and register an <code>at_exit</code> callback to close it, thus guaranteeing the descriptor is not leaked in case the current domain exits.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-cpu_relax"><a href="#val-cpu_relax" class="anchor"></a><code><span><span class="keyword">val</span> cpu_relax : <span>unit <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>If busy-waiting, calling cpu_relax () between iterations will improve performance on some CPU architectures</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_main_domain"><a href="#val-is_main_domain" class="anchor"></a><code><span><span class="keyword">val</span> is_main_domain : <span>unit <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>is_main_domain ()</code> returns true if called from the initial domain.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-recommended_domain_count"><a href="#val-recommended_domain_count" class="anchor"></a><code><span><span class="keyword">val</span> recommended_domain_count : <span>unit <span class="arrow">-></span></span> int</span></code></div><div class="spec-doc"><p>The recommended maximum number of domains which should be running simultaneously (including domains already running).</p><p>The value returned is at least <code>1</code>.</p></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-DLS"><a href="#module-DLS" class="anchor"></a><code><span><span class="keyword">module</span> <a href="DLS/index.html">DLS</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Domain-local Storage</p></div></div></div></body></html> |