Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

BlockedIndefinitelyOnMVar thrown with live reference in unrelated finalizer
I am not sure whether this is a bug, but it is certainly unexpected behaviour. The following code throws a BlockedIndefinitelyOnMVar in the forked thread even though the MVar would be eventually written to by an unrelated finalizer: ```hs import Control.Concurrent import Data.IORef main :: IO () main = do mvar <- newEmptyMVar -- _ <- forkIO $ threadDelay 9999999999999 >> isEmptyMVar mvar >> return () ref <- newIORef () -- unrelated IORef _ <- mkWeakIORef ref (putMVar mvar ()) -- register finalizer _ <- forkFinally (takeMVar mvar :: IO ()) print threadDelay 1000000 ``` And indeed, if the forkIO line is uncommented no exception is thrown, as the new thread keeps another live reference to the MVar. Is this intended behaviour? Why does the MVar reference in the finalizer not count for BlockedIndefinitelyOnMVar? (A similar thing happens with STM primitives.) <details><summary>Trac metadata</summary> | Trac field | Value | | ---------------------- | -------------- | | Version | 7.10.2 | | Type | Bug | | TypeOfFailure | OtherFailure | | Priority | normal | | Resolution | Unresolved | | Component | Runtime System | | Test case | | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | simonmar | | Operating system | | | Architecture | | </details> <!-- {"blocked_by":[],"summary":"BlockedIndefinitelyOnMVar thrown with live reference in unrelated finalizer","status":"New","operating_system":"","component":"Runtime System","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.2","keywords":["BlockedIndefinitelyOnMVar","finalize"],"differentials":[],"test_case":"","architecture":"","cc":["simonmar"],"type":"Bug","description":"I am not sure whether this is a bug, but it is certainly unexpected behaviour. The following code throws a BlockedIndefinitelyOnMVar in the forked thread even though the MVar would be eventually written to by an unrelated finalizer:\r\n\r\n{{{#!hs\r\nimport Control.Concurrent\r\nimport Data.IORef\r\n\r\nmain :: IO ()\r\nmain = do\r\n mvar <- newEmptyMVar\r\n -- _ <- forkIO $ threadDelay 9999999999999 >> isEmptyMVar mvar >> return ()\r\n ref <- newIORef () -- unrelated IORef\r\n _ <- mkWeakIORef ref (putMVar mvar ()) -- register finalizer\r\n _ <- forkFinally (takeMVar mvar :: IO ()) print\r\n threadDelay 1000000\r\n}}}\r\n\r\nAnd indeed, if the forkIO line is uncommented no exception is thrown, as the new thread keeps another live reference to the MVar. Is this intended behaviour? Why does the MVar reference in the finalizer not count for BlockedIndefinitelyOnMVar?\r\n\r\n(A similar thing happens with STM primitives.)","type_of_failure":"OtherFailure","blocking":[]} -->
issue