how to implement timeouts for IO operations?

Johannes Waldmann joe@isun.informatik.uni-leipzig.de
Wed, 18 Apr 2001 14:52:12 +0200 (MET DST)


what is the Right Way to impose a timeout condition on IO actions?
the GHC manual says ( http://www.haskell.org/ghc/docs/5.00/set/select.html )
"use threadDelay and  asynchronous exceptions". When I do this:

timed :: Int -> IO a -> IO a
timed d action = do

    let timer = do	  
	    threadDelay d
	    throw $ AssertionFailed "timer expired"

    t <- forkIO timer
    x <- action
    killThread t
    return x

it seems to work, but how do I turn off the "Fail: thread killed" messages?

-- 
-- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ --
-- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/252 --