From 50fafbea08bea75019ebde157f51539fa04ba2c0 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 20 Apr 2004 15:52:18 +0000 Subject: [PATCH] [project @ 2004-04-20 15:52:18 by simonmar] New version of fixIO which does eager blackholing. --- System/IO.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/System/IO.hs b/System/IO.hs index 877623a..f2a412c 100644 --- a/System/IO.hs +++ b/System/IO.hs @@ -375,8 +375,17 @@ hPrint hdl = hPutStrLn hdl . show -- fixIO #ifdef __GLASGOW_HASKELL__ -fixIO :: (a -> IO a) -> IO a -fixIO m = stToIO (fixST (ioToST . m)) +fixIO :: (a -> IO a) -> IO a +fixIO k = do + ref <- newIORef (throw NonTermination) + ans <- unsafeInterleaveIO (readIORef ref) + result <- k ans + writeIORef ref result + return result + +-- NOTE: we do our own explicit black holing here, because GHC's lazy +-- blackholing isn't enough. In an infinite loop, GHC may run the IO +-- computation a few times before it notices the loop, which is wrong. #endif -- $locking -- 1.7.10.4