
Hi ghc users, I have a program, written in a mixture of Haskell and C, in which the C part is supposed to handle a ^C interrupt, accomplished through the usual signal() call. It works as expected when the Haskell part is compiled by nhc98. But when it is compiled by ghc, for some reason the ghc RTS appears to trap the interrupt itself, and halts the program with the message prog: interrupted instead of allowing the newly installed C signal handler to run. I have looked through the ghc user manual for some means to turn off or divert the RTS signal-handling, but I couldn't find anything relevant. The nearest thing is Exception.block, which excludes an asynchronous exception from happening whilst the `block' is in operation, but that doesn't seem to stop a ^C from interrupting the program, so I guess that isn't its real purpose. So, what should I use instead? Regards, Malcolm

So, what should I use instead?
This is just a guess until someone who actually knows what they're talking about answers, but... In /ghc/rts/Schedule.c, there's a function: void interruptStgRts(void) { interrupted = 1; context_switch = 1; } which basically tells the rts to emit an interrupted message here: /* If we're interrupted (the user pressed ^C, or some other * termination condition occurred), kill all the currently running * threads. */ if (interrupted) { IF_DEBUG(scheduler, sched_belch("interrupted")); deleteAllThreads(); interrupted = rtsFalse; was_interrupted = rtsTrue; } My guess is that if you override the interruptStgRts function as per section 4.16.4 in the ghc users guide, you should be able to fix this problem. Simply overriding it with a function that *doesn't* set interrupted to 1 should be fine (you shouldn't need to set context_switch to 1 either). Don't kill me if this doesn't work though :) - Hal
participants (2)
-
Hal Daume III
-
Malcolm Wallace