#637: Ctrl-Break handler doesn't work in forked threads in "-threaded" RTS
--------------------------------+-------------------------------------------
  Reporter:  [EMAIL PROTECTED]  |          Owner:  simonmar
      Type:  bug                |         Status:  new     
  Priority:  normal             |      Milestone:  6.4.2   
 Component:  Runtime System     |        Version:  6.4.1   
  Severity:  normal             |     Resolution:          
  Keywords:                     |             Os:  Unknown 
Difficulty:  Unknown            |   Architecture:  Unknown 
--------------------------------+-------------------------------------------
Changes (by simonmar):

  * milestone:  => 6.4.2

Old description:

> The following program demonstrates bug in 6.4.1 (6.4.0 was ok).
> if you compile it with "-threaded", run and press Ctrl-Break, you will
> see message "main.EXE: <stdin>: hGetLine: end of file" and program
> blocks (because forked thread is dead). the problem is that installed
> ctrl-break handler don't called in forked threads
>
> if you compile program without "-threaded" or with 6.4.0, it works as
> expected - pressing Ctrl-Break runs my handler so you will see
> "^Break! main.EXE: thread killed" message
>

>
> import Control.Concurrent
> import Control.Exception
> import GHC.ConsoleHandler
>
> handleCtrlBreak action = do
>   myThread <- myThreadId
>   let onBreak event = do
>         putStrLn " ^Break!"
>         killThread myThread
>   bracket (installHandler$ Catch onBreak) (installHandler) $  \oldHandler
> -> do
>     action
>
> main =  do
>   handleCtrlBreak $ do
>     x <- newEmptyMVar
>     forkIO$ do a <- getLine
>                print a
>                putMVar x ()
>                return ()
>     takeMVar x
>     return ()

New description:

 The following program demonstrates bug in 6.4.1 (6.4.0 was ok).
 if you compile it with "-threaded", run and press Ctrl-Break, you will
 see message "main.EXE: <stdin>: hGetLine: end of file" and program
 blocks (because forked thread is dead). the problem is that installed
 ctrl-break handler don't called in forked threads

 if you compile program without "-threaded" or with 6.4.0, it works as
 expected - pressing Ctrl-Break runs my handler so you will see
 "Break! main.EXE: thread killed" message


 {{{
 import Control.Concurrent
 import Control.Exception
 import GHC.ConsoleHandler

 handleCtrlBreak action = do
   myThread <- myThreadId
   let onBreak event = do
         putStrLn " ^Break!"
         killThread myThread
   bracket (installHandler$ Catch onBreak) (installHandler) $  \oldHandler
 -> do
     action

 main =  do
   handleCtrlBreak $ do
     x <- newEmptyMVar
     forkIO$ do a <- getLine
                print a
                putMVar x ()
                return ()
     takeMVar x
     return ()
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/637>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to