> IMHO this program should not print "Fail: thread killed". Removing
> the first threadDelay causes the message to disappear. It can be
> worked around by catching the exception in the thread to be killed.
> 
> import Concurrent
> 
> kill:: IO ()
> kill = do
>     result   <- newEmptyMVar
>     finished <- newMVar ()
>     t1 <- forkIO $ do
>         threadDelay 1
>         takeMVar finished
>         putMVar result ()
>     t2 <- forkIO $ do
>         threadDelay 1000000
>         takeMVar finished
>         putMVar result ()
>     takeMVar result
>     killThread t2
> 
> main:: IO ()
> main = kill >> kill

There's a default exception handler installed on all threads forked with
forkIO, which prints on stderr any exception caught.  Is that your
objection?  If so, you can define a version of forkIO with your own default
exception handler - copy the definition of forkIO in
hslibs/lang/concurrent/Concurrent.lhs, and replace "topHandler" with your
own handler.

It isn't wise to remove the handler altogether, because an uncaught
exception is currently an error in the RTS.  This should be fixed.

Cheers,
        Simon

Reply via email to