<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Thanks Carsten, I've compiled&nbsp;your example and all works as expected.<BR>
&nbsp;<BR>
Just a note.<BR>
If I load the module in GHCi (intead of compiling it) and launch main function the result is quite strange. I obtain:<BR>
&nbsp;<BR>
He lwloorld<BR>
[(),()]<BR>
&nbsp;<BR>
Luca.<BR>&nbsp;<BR>&gt; To: glasgow-haskell-users@haskell.org<BR>&gt; From: carsten@codimi.de<BR>&gt; Date: Mon, 12 Oct 2009 13:34:36 +0200<BR>&gt; Subject: Re: STM experiment<BR>&gt; <BR>&gt; Brent Yorgey schrieb:<BR>&gt; &gt; On Fri, Oct 02, 2009 at 06:16:49PM +0200, Luca Ciciriello wrote:<BR>&gt; &gt;&gt; Compiling this module with:<BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt; ghc --make Main.hs -o Main<BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt; and launcing ./Main the result is just:<BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt; Terminal&gt; <BR>&gt; &gt; <BR>&gt; &gt; Also, the reason you only get "world" here is likely because the main<BR>&gt; &gt; thread prints "world" and exits before the forked thread even gets a<BR>&gt; &gt; chance to run. If you want the main thread to wait for the forked<BR>&gt; &gt; thread you must explicitly synchronize them; the most common way to do<BR>&gt; &gt; this is to set up an MVar (or a TVar in STM code) which the main<BR>&gt; &gt; thread reads from, and the forked thread writes to when it is<BR>&gt; &gt; finished in order to signal the main thread.<BR>&gt; <BR>&gt; For example, using a utility function I wrote some time ago:<BR>&gt; <BR>&gt; <BR>&gt; module Main(main) where<BR>&gt; <BR>&gt; import IO<BR>&gt; import Control.Concurrent<BR>&gt; <BR>&gt; parallel :: [IO a] -&gt; IO [a]<BR>&gt; parallel = foldr (\a c -&gt;<BR>&gt; do<BR>&gt; v &lt;- newEmptyMVar<BR>&gt; forkIO (a &gt;&gt;= putMVar v)<BR>&gt; xs &lt;- c<BR>&gt; x &lt;- takeMVar v<BR>&gt; return (x:xs))<BR>&gt; (return [])<BR>&gt; <BR>&gt; main = parallel [hPutStr stdout "Hello", hPutStr stdout " world\n"]<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; There might be better ways to do this, but I hope that this will also be<BR>&gt; interesting because of the functional abstractions that are used. Note<BR>&gt; that this will execute two forkIOs, not one as the original code. If<BR>&gt; that is not desirable, foldr1 could have been used.<BR>&gt; <BR>&gt; Best<BR>&gt; <BR>&gt; Carsten<BR>&gt; <BR>&gt; <BR>&gt; _______________________________________________<BR>&gt; Glasgow-haskell-users mailing list<BR>&gt; Glasgow-haskell-users@haskell.org<BR>&gt; http://www.haskell.org/mailman/listinfo/glasgow-haskell-users<BR>                                               <br /><hr />New! Receive and respond to mail from other email accounts from within Hotmail <a href='http://clk.atdmt.com/UKM/go/167688463/direct/01/' target='_new'>Find out how.</a></body>
</html>