[GHC] #8804: BlockedIndefinitelyOnMVar thrown for an MVar which is still weakly accessible from another thread
GHC
ghc-devs at haskell.org
Wed Feb 19 20:03:28 UTC 2014
#8804: BlockedIndefinitelyOnMVar thrown for an MVar which is still weakly
accessible from another thread
--------------------------+------------------------------------------------
Reporter: bholst | Owner: simonmar
Type: bug | Status: new
Priority: normal | Milestone:
Component: | Version: 7.6.3
Runtime System | Operating System: Unknown/Multiple
Keywords: | Type of failure: Incorrect result at runtime
Architecture: | Test Case:
Unknown/Multiple | Blocking:
Difficulty: |
Unknown |
Blocked By: |
Related Tickets: |
--------------------------+------------------------------------------------
GHC's runtime system throws a BlockedIndefinatelyOnMVar exception
when the thread blocking an the MVar is the only one having a direct
access to it. It assumes that there will be nothing written into the MVar
in the future.
This would be the correct behaviour if there were no weak references.
The runtime system even throws the Exception when another thread still has
a weak reference to the MVar. Consider the following example:
{{{
import Control.Concurrent
import System.Mem.Weak
import Data.Maybe
import Control.Monad
main = do
m <- newEmptyMVar
w <- mkWeakMVar m (return ())
forkIO $ do
threadDelay 1000000
n <- deRefWeak w
when (isJust n) $ putMVar (fromJust n) ()
takeMVar m
}}}
At the time of ''takeMVar'' the forked thread has a weak reference to
the MVar and it will put a value in it. However, the runtime system throws
the Exception:
{{{
% ghc BlockingOnMVar.hs -threaded
Linking BlockingOnMVar ...
% ./BlockingOnMVar +RTS -N2
BlockingOnMVar: thread blocked indefinitely in an MVar operation
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8804>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list