[GHC] #8804: BlockedIndefinitelyOnMVar thrown for an MVar which is still weakly accessible from another thread
GHC
ghc-devs at haskell.org
Fri Feb 21 08:28:26 UTC 2014
#8804: BlockedIndefinitelyOnMVar thrown for an MVar which is still weakly
accessible from another thread
------------------------------------------------+--------------------------
Reporter: bholst | Owner:
Type: bug | simonmar
Priority: normal | Status: closed
Component: Runtime System | Milestone:
Resolution: invalid | Version: 7.6.3
Operating System: Unknown/Multiple | Keywords:
Type of failure: Incorrect result at runtime | Architecture:
Test Case: | Unknown/Multiple
Blocking: | Difficulty:
| Unknown
| Blocked By:
| Related Tickets:
------------------------------------------------+--------------------------
Comment (by bholst):
You mean the waiting thread is garbage collected in this example and
that's why the MVar will never be filled?
Then keeping the thread reachable through another MVar should do the
trick?
{{{
import Control.Concurrent
import System.Mem.Weak
import Data.Maybe
import Control.Monad
main = do
my <- myThreadId
m <- newEmptyMVar
w <- mkWeakMVar m (return ())
o <- newEmptyMVar
_ <- forkIO $ do
threadDelay 1000000
n <- deRefWeak w
when (isJust n) $ putMVar (fromJust n) ()
putMVar o ()
takeMVar m
takeMVar o
}}}
This program has exactly the same output.
I understand that the ''MVar m'' is not reachable from the other thread,
but nevertheless the main thread is not blocked indefinately on this MVar.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8804#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list