[GHC] #7675: Program lives on with dead main thread

#7675: Program lives on with dead main thread -------------------------+-------------------------------------------------- Reporter: guest | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.2 | Keywords: Os: Linux | Architecture: x86 Failure: None/Unknown | Blockedby: Blocking: | Related: -------------------------+-------------------------------------------------- http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control- Concurrent.html#g:13 says: In a standalone GHC program, only the main thread is required to terminate in order for the process to terminate. Thus all other forked threads will simply terminate at the same time as the main thread (the terminology for this kind of behaviour is "daemonic threads"). This isn't always true in ghc, as the following program demonstrates: {{{ % cat try.hs import Control.Concurrent import Control.Concurrent.STM import Control.Monad import System.Exit main :: IO () main = do x <- newTVarIO 0 forkIO $ forever $ do --atomically $ writeTVar x 42 --yield return () putStrLn "about to exit" exitSuccess putStrLn "dead" }}} {{{ % ghc -fforce-recomp try.hs [1 of 1] Compiling Main ( try.hs, try.o ) Linking try ... % ./try about to exit ^C^C }}} Instead of actually exiting, the program consumes 100% CPU despite the main thread being gone. The behavior is slightly different with `-threaded`: {{{ % ghc -fforce-recomp -threaded try.hs [1 of 1] Compiling Main ( try.hs, try.o ) Linking try ... % ./try ^C^C }}} Here it doesn't even execute the main thread. {{{ % ./try +RTS -N2 try: Using large values for -N is not allowed by default. Link with -rtsopts to allow full control. }}} I don't understand what's up with this. 2 isn't what I'd call "large". {{{ % ghc -fforce-recomp -threaded -rtsopts=all try.hs [1 of 1] Compiling Main ( try.hs, try.o ) Linking try ... % ./try +RTS -N2 about to exit }}} This version works as expected. Anyway, I'm not sure whether this is a bug in the RTS or in the documentation, but they clearly don't agree. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7675 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7675: Program lives on with dead main thread ---------------------------+------------------------------------------------ Reporter: guest | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.2 Resolution: duplicate | Keywords: Os: Linux | Architecture: x86 Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: ---------------------------+------------------------------------------------ Changes (by simonmar): * status: new => closed * difficulty: => Unknown * resolution: => duplicate Comment: The main bug is an instance of #367. You can make it work with 7.8.1 using `-fno-omit-yields` and compiling with -O to ensure that enough stuff gets inlined (otherwise you'd need to compile the libraries with `-fno- omit-yields` too). A "large value of -N" is one that is greater than the number of cores in your machine. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7675#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC