[Haskell-beginners] threadDelay does not delay thread execution?

Benjamin Edwards edwards.benj at gmail.com
Mon Jul 5 05:51:58 EDT 2010


Hi All,

I am looking to make a simple program that polls an interface once a second
or so. I thought  I could use threadDelay for this, so knocked up the
following toy program to test my idea.

module TD
  where

import Control.Concurrent
import Control.Concurrent.MVar

main :: IO ()
main = do mv <- newEmptyMVar
          forkIO $ loop mv 0 "Hai"
          takeMVar mv
          return ()
  where loop mv n msg = do putStrLn msg
                           threadDelay 10000
                           if n < 10 then loop mv (n+1) msg
                                     else putMVar mv ()

It doesn't work, in as much as I see all the messages printed seemingly as
fast as Std out will print them. What am I doing wrong?

All help is much appreciated,
Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100705/123bfbb4/attachment-0001.html


More information about the Beginners mailing list