[Haskell-cafe] Re: Threads not running under GHC 6.10?

Simon Marlow marlowsd at gmail.com
Mon Dec 15 09:00:37 EST 2008

Gwern Branwen wrote:
> Hash: SHA512
> So, the Hint library was recently updated and I was editing Mueval to
> run with (i386) 6.10, when I discovered that for some reason, DoS'ing
> expressions were succeeding in rendering my machine unusable.
> Eventually, I discovered that my watchdog thread didn't seem to be
> running. But with +RTS -N2 -RTS all my tests did pass!
> Here's a simple example of what I mean; the following is basically a
> very lightly adapted version of the actual Mueval code:
> - ----------------
> import Control.Concurrent   (forkIO, killThread, myThreadId,
> threadDelay, throwTo, yield, ThreadId)
> import System.Posix.Signals (sigXCPU, installHandler, Handler(CatchOnce))
> import Control.OldException (Exception(ErrorCall))
> main :: IO ()
> main = do tid  ThreadId -> IO ()
> watchDog tout tid = do installHandler sigXCPU
>                                           (CatchOnce
>                                            $ throwTo tid $ ErrorCall
> "Time limit exceeded.") Nothing
>                        forkIO $ do threadDelay (tout * 100000)
>                                    -- Time's up. It's a good day to die.
>                                    throwTo tid (ErrorCall "Time limit exceeded")
>                                    yield -- give the other thread a chance
>                                    killThread tid -- Die now, srsly.
>                                    error "Time expired"
>                        return () -- Never reached. Either we error out in
>                                  -- watchDog, or the evaluation thread finishes.

This particular example illustrates a bug in 6.10.1 that we've since fixed:


However in general you can still write expressions that don't allocate 
anything (e.g. nfib 1000), and your watchdog thread won't get a chance to 
run unless there's a spare CPU available (+RTS -N2).


More information about the Haskell-Cafe mailing list