
28 Jan
2007
28 Jan
'07
7:16 a.m.
On 26.01 23:48, Peter Simons wrote:
timeout :: Int -> IO a -> IO (Maybe a) timeout n f | n < 0 = fmap Just f | n == 0 = return Nothing | otherwise = do pid <- myThreadId ex <- fmap Timeout newUnique handleJust (\e -> dynExceptions e >>= fromDynamic >>= guard . (ex ==)) (\_ -> return Nothing) (bracket (forkIO (threadDelay n >> throwDynTo pid ex)) (killThread) (\_ -> fmap Just f))
This seems broken on GHC with FFI. The thread gets blocked on a FFI call that blocks forever and thus the timeout exception is not delivered - if I remember things correctly. - Einar Karttunen