> I'm trying to write some code that catches unix signals and turns them
> into GHC exceptions, GHC version 6.0, debian linux
> 
> Heres my code:
> 
> ------
>    module Main where
>    
>    import Control.Concurrent
>    import Control.Exception
>    import System.Posix
>    import IO 
>    
>    catchCtrlC :: IO Handler
>    catchCtrlC
>       = do main_thread <- myThreadId
>            installHandler sigINT (Catch (handler main_thread)) Nothing
>            where
>            handler :: ThreadId -> IO ()
>            handler main_thread = throwTo main_thread 
> (ErrorCall "Kaboom")
>    
>    main :: IO ()
>    main = do catchCtrlC 
>              print (f 1)
>    
>    f :: Int -> Int
>    f x = f (x + 1)
> ------   
> 
> The function "f" is intentionally bogus, I want it to loop so 
> I have enough time to hit cntrl-C.

You've hit a known bug with concurrency, described in the
Control.Concurrent documentation.

The problem is that context switches only happen when some allocation is
going on: in your f function above, the optimiser turns it into a loop
that does no allocation, so no context switches can happen and the
exception is never delivered.

You probably won't run into this bug in a real program ;-)

Cheers,
        Simon

_______________________________________________
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to