[GHC] #8209: Race condition in setNumCapabilities
GHC
ghc-devs at haskell.org
Sun Sep 1 16:24:14 CEST 2013
#8209: Race condition in setNumCapabilities
----------------------------------+-------------------------------------
Reporter: akio | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Runtime System | Version: 7.7
Keywords: | Operating System: Unknown/Multiple
Architecture: x86_64 (amd64) | Type of failure: Runtime crash
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
----------------------------------+-------------------------------------
In HEAD, the following program sometimes deadlocks (about 1/10 of the
time).
{{{
import Control.Concurrent
import Control.Monad
import GHC.Conc
main = do
mainTid <- myThreadId
labelThread mainTid "main"
forM_ [0..0] $ \i -> forkIO $ do
subTid <- myThreadId
labelThread subTid $ "sub " ++ show i
forM_ [0..100000000] $ \j -> putStrLn $ "sub " ++ show i ++ ": " ++
show j
yield
setNumCapabilities 2
}}}
The problem seems to be that there is a race condition between
setNumCapabilites and a Task returning from a foreign call. Specifically,
a sequence of events like the following can happen:
1. Task 0 makes a foreign call.
2. Task 1 calls setNumCapabilities()
3. The call on task 0 returns; it reads task->cap from the memory.
4. Task 1 moves the Capabilities, invalidating all pointers to them.
5. Task 0 takes over the invalidated Capability.
The attached patch adds an ASSERT to the RTS to demonstrate the problem
(it does not fix the problem).
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8209>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list