#4509: System.Timeout inoperative with Data.IORef
---------------------------------+------------------------------------------
Reporter: warren | Owner:
Type: bug | Status: new
Priority: normal | Component: Runtime System
Version: 7.0.1 | Keywords:
Testcase: | Blockedby:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
I would like to write some code that gathers as many answers as possible
within a certain time period. Seems like System.Timeout is what I need,
but it doesn't appear to work when the IO monad only uses IORefs rather
than read/write calls. The documentation doesn't mention anything about
System.Timeout having this limitation.
I would guess that there needs to be some way for IO operations to check
for timeouts, even if they don't register a file descriptor with the IO
manager.
Here's some sample code that highlights the problem:
import Data.IORef
import System.Timeout
fib:: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
runFibs accum i = do
let v = fib i
modifyIORef accum (\l -> (i,v):l)
--putStrLn $ show (i, v) -- add this back, and it works
runFibs accum (i+1)
main = do
accum <- newIORef []
timeout 10000 (runFibs accum 1)
rv <- readIORef accum
putStrLn $ show rv
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4509>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs