[GHC] #8804: BlockedIndefinitelyOnMVar thrown for an MVar which is still weakly accessible from another thread

GHC ghc-devs at haskell.org
Fri Feb 21 09:57:51 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 ezyang):

 I suspect you typoed, because `my` becomes dead immediately in your code.
 An MVar will not keep a thread alive unless the thread is blocked on it.
 If you force the thread to be live it will not get the exception raised,
 since the thread now retains the MVar.

 {{{
 import Control.Concurrent
 import System.Mem.Weak
 import Data.Maybe
 import Control.Monad
 import Foreign.StablePtr

 main = do
   my <- myThreadId
   newStablePtr my
   m <- newEmptyMVar
   w <- mkWeakMVar m (return ())
   _ <- forkIO $ do
     threadDelay 1000000
     n <- deRefWeak w
     when (isJust n) $ putMVar (fromJust n) ()
   takeMVar m
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8804#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list