<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">From: Jiansen He &lt;<a href="mailto:jiansenhe@googlemail.com">jiansenhe@googlemail.com</a>&gt;<br>

<br>
Hi cafe,<br>
<br>
I wounder if it is possible to tell a haskell system that two computations<br>
with side effects could be executed concurrently.<br>
<br>
Here is an affected example:<br>
<br>
Suppose two people want to compare their age, but do not want to leak their<br>
personal information.  The following program reads one person&#39;s age after<br>
another then send back compared result.<br>
<br>
age :: IO ()<br>
age  = do<br>
  i &lt;- readIntFrom a<br>
  j &lt;- readIntFrom b<br>
 writeTo a (i-j)<br>
 writeTo b (j-i)<br>
<br>
How can I express the fact that two readings could be carried out in any<br>
order?</blockquote><div><br></div><div>The best approach is probably to fork a thread for each concurrent evaluation.  There are a few packages on Hackage that can help with this; I&#39;ve used threads[1] and spawn[2] successfully.</div>
<div><br></div><div>If the &quot;readIntFrom&quot; function is meant to be responding to a client, a threaded model may make sense organizationally, but for this to be a performance benefit there needs to be sufficient work for each thread to carry out.  Haskell threads are lighter than Posix threads, but there&#39;s still overhead involved.</div>
<div><br></div><div>There is an alternative I hesitate to mention because it involves some voodoo, but Roman Leshchinskiy came up with a clever technique that might be appropriate if you want the behavior of &quot;par&quot; but for IO[3].</div>
<div><br></div><div>[1] <a href="http://hackage.haskell.org/package/threads">http://hackage.haskell.org/package/threads</a></div><div>[2] <a href="http://hackage.haskell.org/package/spawn">http://hackage.haskell.org/package/spawn</a></div>
<div>[3] <a href="http://unlines.wordpress.com/2010/04/21/sparking-imperatives/">http://unlines.wordpress.com/2010/04/21/sparking-imperatives/</a></div></div>