<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="AsciiDoc 8.6.8">
<title>ConcurrentML</title>
<link rel="stylesheet" href="./asciidoc.css" type="text/css">
<link rel="stylesheet" href="./pygments.css" type="text/css">


<script type="text/javascript" src="./asciidoc.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
asciidoc.install();
/*]]>*/
</script>
<link rel="stylesheet" href="./mlton.css" type="text/css"/>
</head>
<body class="article">
<div id="banner">
<div id="banner-home">
<a href="./Home">MLton 20130715</a>
</div>
</div>
<div id="header">
<h1>ConcurrentML</h1>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p><a href="http://cml.cs.uchicago.edu/">Concurrent ML</a> is an SML concurrency
library based on synchronous message passing.  MLton has an initial
port of CML from SML/NJ, but is missing a thread-safe wrapper around
the Basis Library and event-based equivalents to <span class="monospaced">IO</span> and <span class="monospaced">OS</span>
functions.</p></div>
<div class="paragraph"><p>All of the core CML functionality is present.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">structure</span><span class="w"> </span><span class="n">CML</span><span class="p">:</span><span class="w"> </span><span class="n">CML</span><span class="w"></span>
<span class="k">structure</span><span class="w"> </span><span class="n">SyncVar</span><span class="p">:</span><span class="w"> </span><span class="n">SYNC_VAR</span><span class="w"></span>
<span class="k">structure</span><span class="w"> </span><span class="n">Mailbox</span><span class="p">:</span><span class="w"> </span><span class="n">MAILBOX</span><span class="w"></span>
<span class="k">structure</span><span class="w"> </span><span class="n">Multicast</span><span class="p">:</span><span class="w"> </span><span class="n">MULTICAST</span><span class="w"></span>
<span class="k">structure</span><span class="w"> </span><span class="n">SimpleRPC</span><span class="p">:</span><span class="w"> </span><span class="n">SIMPLE_RPC</span><span class="w"></span>
<span class="k">structure</span><span class="w"> </span><span class="n">RunCML</span><span class="p">:</span><span class="w"> </span><span class="n">RUN_CML</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>The <span class="monospaced">RUN_CML</span> signature is minimal.</p></div>
<div class="listingblock">
<div class="content"><div class="highlight"><pre><span class="k">signature</span><span class="w"> </span><span class="n">RUN_CML</span><span class="w"> </span><span class="p">=</span><span class="w"></span>
<span class="w">   </span><span class="k">sig</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">isRunning</span><span class="p">:</span><span class="w"> </span><span class="n">unit</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">bool</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">doit</span><span class="p">:</span><span class="w"> </span><span class="p">(</span><span class="n">unit</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">unit</span><span class="p">)</span><span class="w"> </span><span class="n">*</span><span class="w"> </span><span class="n">Time</span><span class="p">.</span><span class="n">time</span><span class="w"> </span><span class="n">option</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">OS</span><span class="p">.</span><span class="n">Process</span><span class="p">.</span><span class="n">status</span><span class="w"></span>
<span class="w">      </span><span class="k">val</span><span class="w"> </span><span class="n">shutdown</span><span class="p">:</span><span class="w"> </span><span class="n">OS</span><span class="p">.</span><span class="n">Process</span><span class="p">.</span><span class="n">status</span><span class="w"> </span><span class="p">-&gt;</span><span class="w"> </span><span class="n">&#39;a</span><span class="w"></span>
<span class="w">   </span><span class="k">end</span><span class="w"></span>
</pre></div></div></div>
<div class="paragraph"><p>MLton&#8217;s <span class="monospaced">RunCML</span> structure does not include all of the cleanup and
logging operations of SML/NJ&#8217;s <span class="monospaced">RunCML</span> structure.  However, the
implementation does include the <span class="monospaced">CML.timeOutEvt</span> and <span class="monospaced">CML.atTimeEvt</span>
functions, and a preemptive scheduler that knows to sleep when there
are no ready threads and some threads blocked on time events.</p></div>
<div class="paragraph"><p>Because MLton does not wrap the Basis Library for CML, the "right" way
to call a Basis Library function that is stateful is to wrap the call
with <span class="monospaced">MLton.Thread.atomically</span>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_usage">Usage</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
You can import the CML Library into an MLB file with:
</p>
<table class="tableblock frame-all grid-all"
style="
width:100%;
">
<col style="width:50%;">
<col style="width:50%;">
<thead>
<tr>
<th class="tableblock halign-left valign-top" >MLB file</th>
<th class="tableblock halign-left valign-top" >Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top" ><p class="tableblock"><span class="monospaced">$(SML_LIB)/cml/cml.mlb</span></p></td>
<td class="tableblock halign-left valign-top" ><p class="tableblock"></p></td>
</tr>
</tbody>
</table>
</li>
<li>
<p>
If you are porting a project from SML/NJ&#8217;s <a href="CompilationManager">CompilationManager</a> to
MLton&#8217;s <a href="MLBasis"> ML Basis system</a> using <span class="monospaced">cm2mlb</span>, note that the
following map is included by default:
</p>
<div class="listingblock">
<div class="content monospaced">
<pre># CML Library
$cml                                    $(SML_LIB)/cml
$cml/cml.cm                             $(SML_LIB)/cml/cml.mlb</pre>
</div></div>
<div class="paragraph"><p>This will automatically convert a <span class="monospaced">$cml/cml.cm</span> import in an input <span class="monospaced">.cm</span> file into a <span class="monospaced">$(SML_LIB)/cml/cml.mlb</span> import in the output <span class="monospaced">.mlb</span> file.</p></div>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_also_see">Also see</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
<a href="ConcurrentMLImplementation">ConcurrentMLImplementation</a>
</p>
</li>
<li>
<p>
<a href="eXene">eXene</a>
</p>
</li>
</ul></div>
</div>
</div>
</div>
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
</div>
<div id="footer-badges">
</div>
</div>
</body>
</html>
