basvandijk/threads — Issue #3: how do you kill a threadgroup?
Author: mwotton
Created: 2012-03-09 22:34:02+00:00
State: open

I'd like to be able to intercept sigINT to shut down a server cleanly, so I can get profiling information out of it. however, when I try to install a signal handler, like so:

cleanly :: IO () -> IO ()
cleanly action = do
tid <- CC.forkIO action
flag <- newEmptyMVar
_ <- installHandler sigINT (CatchOnce $ do
Prelude.putStrLn "Caught an interrupt"
CC.killThread tid
putMVar flag ()) Nothing
takeMVar flag

where action is something that starts a new threadgroup, killing the thread id that action returns doesn't seem to kill all of the child threads. What's the correct way of doing this?