STM experiment

Brent Yorgey byorgey at
Fri Oct 2 13:34:06 EDT 2009

On Fri, Oct 02, 2009 at 06:16:49PM +0200, Luca Ciciriello wrote:
> Compiling this module with:
> ghc --make Main.hs -o Main
> and launcing ./Main the result is just:
> Terminal> world

Also, the reason you only get "world" here is likely because the main
thread prints "world" and exits before the forked thread even gets a
chance to run.  If you want the main thread to wait for the forked
thread you must explicitly synchronize them; the most common way to do
this is to set up an MVar (or a TVar in STM code) which the main
thread reads from, and the forked thread writes to when it is
finished in order to signal the main thread.


More information about the Glasgow-haskell-users mailing list