[Haskell] timing/timeout (how to express that in Haskell)

Mirko Rahn rahn at ira.uka.de
Fri May 12 08:42:02 EDT 2006


> PS: I am still curious: does threadDelay use
> the wall clock or the per-process clock (CPU time)?
> And regardless of the answer - how could one obtain
> the opposite behaviour? (I don't find this discussed
> in the visible docs. Or am I missing something?)

I think it uses wall clock time. Proof:

*NG> System.Time.getClockTime >>= print >> GHC.Conc.threadDelay (10^7) 
 >> System.Time.getClockTime >>= print
Fri May 12 14:36:55 CEST 2006
Fri May 12 14:37:05 CEST 2006
(0.01 secs, 803092 bytes)

Delayed 10 secs without using CPU.

BTW: Using the proposed watchdogIO-function I can observe the following 
behavior:

*NG> Util.IO.Within.withinIO 10 ( GHC.Conc.threadDelay 10000 >> print 
"expensive" ) ( print "cheap" )
"expensive"
"cheap"
*NG> Util.IO.Within.withinIO 10 ( GHC.Conc.threadDelay 10000 >> print 
"expensive" ) ( print "cheap" )
"expensive"
"cheap"
*NG> Util.IO.Within.withinIO 10 ( GHC.Conc.threadDelay 10000 >> print 
"expensive" ) ( print "cheap" )
"expensive"
"cheap"

Uhhh, something's wrong here, *both* functions are executed...

-- 
-- Mirko Rahn -- Tel +49-721 608 7504 --
--- http://liinwww.ira.uka.de/~rahn/ ---


More information about the Haskell mailing list