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

GHC cvs-ghc at haskell.org
Fri Feb 8 14:04:29 CET 2013


#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



More information about the ghc-tickets mailing list