#5421: <<loop>> in withMVar (reproducible, but with large test case)
-------------------------------+--------------------------------------------
Reporter: JohnMillikin | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.2.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Linux | Blocking:
Architecture: x86_64 (amd64) | Failure: Incorrect result at runtime
-------------------------------+--------------------------------------------
Comment(by simonmar):
The cause is quite simple in fact. Here's the definition of `fixIO`, from
`GHC.IO`:
{{{
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
}}}
So if you pull on `ans` before it is ready, you get `<<loop>>`. It loops
for me with 7.0.3.
We could have a cleverer version of `fixIO` in which child threads that
demanded the result would block until the main thread is ready - indeed,
changing the `IORef` to an `MVar` ought to do the trick, although it would
have an extra cost, and if you pulled on the result before it was ready in
the parent thread you would get `BlockedIndefinitelyOnMVar` instead of
`NonTermination`.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5421#comment:5>
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