Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,246
    • Issues 5,246
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 562
    • Merge requests 562
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8209
Closed
Open
Issue created Sep 01, 2013 by takano-akio@takano-akioReporter

Race condition in setNumCapabilities

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).

Trac metadata
Trac field Value
Version 7.7
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Runtime System
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking