Along similar lines: I have a Twelf top-level function in server that should interrupt the current computation and return to the Twelf top-level, not to an ML debugger or the ML top-level. I saw the documentation on signals, but I don't see how to achieve the desired effect because the handler will be run in a different thread.
Any advice or help would be appreciated.
- Frank
Frank> Along similar lines: I have a Twelf top-level function in Frank> server that should interrupt the current computation and return Frank> to the Twelf top-level, not to an ML debugger or the ML Frank> top-level. I saw the documentation on signals, but I don't see Frank> how to achieve the desired effect because the handler will be Frank> run in a different thread.
I was just thinking about this the other day. I don't think it's currently possible in PolyML to handle asynchronous events - the garbage collector probably assumes it can't happen. So the best approximation I came up with was to code a trivial signal handler in C that sets an "interrupted" flag and checking that flag periodically in my main loop.
Of course, that assumes you have an identifiable "main loop" other than the toplevel ...
It would be very inconvenient to rewrite the code to to check for interrupts as you suggest.
The built-in SIGINT handler does almost what I want, because it stops execution of the main thread and also allows throwing the Interrupt exception. So it looks like it is implemented with some primitives that are not available to the programmer. Any chance those could be exported, somehow? Or perhaps another standard signal handler could be made available that simply raises the Interrupt exception?
This is presently not a high priority, because I decided to leave the standard SIGINT handler in place, in which case it is up to the user to just type `f'.
- Frank
Frank> Along similar lines: I have a Twelf top-level function in Frank> server that should interrupt the current computation and return Frank> to the Twelf top-level, not to an ML debugger or the ML Frank> top-level. I saw the documentation on signals, but I don't see Frank> how to achieve the desired effect because the handler will be Frank> run in a different thread.
I was just thinking about this the other day. I don't think it's currently possible in PolyML to handle asynchronous events - the garbage collector probably assumes it can't happen. So the best approximation I came up with was to code a trivial signal handler in C that sets an "interrupted" flag and checking that flag periodically in my main loop.
Of course, that assumes you have an identifiable "main loop" other than the toplevel ...
-- Ian Zimmerman, Oakland, California, U.S.A. if (sizeof(signed) > sizeof(unsigned) + 4) { delete this; } GPG: 433BA087 9C0F 194F 203A 63F7 B1B8 6E5A 8CA3 27DB 433B A087 _______________________________________________ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
On Friday, Dec 20, 2002, at 21:24 Europe/London, Frank Pfenning wrote:
Along similar lines: I have a Twelf top-level function in server that should interrupt the current computation and return to the Twelf top-level, not to an ML debugger or the ML top-level. I saw the documentation on signals, but I don't see how to achieve the desired effect because the handler will be run in a different thread.
Any advice or help would be appreciated.
I'm not certain I've understand this exactly but I think maybe the Process.interruptConsoleProcesses function may do what you want. Processes (i.e. threads) are divided into those that receive the SML90.Interrupt exception (console processes) and those that do not. The Interrupt exception is sent to a console process in one of three cases: 1. If Process.interruptConsoleProcesses is called all console processes are interrupted 2. When a process is created using Process.console a function is returned which when called raises Interrupt in that process only. 3. All console processes will receive an Interrrupt exception when ^C is pressed followed by "f", provided the handling of ^C has not been changed using Signal.signal. It is possible to change the handling of ^C so that it raises an interrupt immediately (rather than producing the => prompt) using Signal.signal(2, Signal.SIG_HANDLE(fn _ => Process.interruptConsoleProcesses())); This is what Isabelle does from what I recall.
Regards, David.
David> All console processes will receive an Interrrupt exception when David> ^C is pressed followed by "f", provided the handling of ^C has David> not been changed using Signal.signal. It is possible to change David> the handling of ^C so that it raises an interrupt immediately David> (rather than producing the => prompt) using
Signal.signal(2, Signal.SIG_HANDLE(fn _ => Process.interruptConsoleProcesses()));
Sorry for my previous uninformed post; I was completely unaware of Signal.signal. I had read the Basis report and looked hard in the POSIX part, and I concluded this wasn't possible. It didn't occur to me there was a PolyML specific toplevel structure for it.
Thanks for the information!
Thanks---this does exactly what I want. It'll be incorporated into the next revision.
Best, Frank
Date: Mon, 30 Dec 2002 13:55:34 +0000 To: Frank Pfenning fp@cs.cmu.edu CC: polyml@inf.ed.ac.uk From: David Matthews David.Matthews@deanvillage.com Subject: Re: [polyml] Handling Interrupts
On Friday, Dec 20, 2002, at 21:24 Europe/London, Frank Pfenning wrote:
Along similar lines: I have a Twelf top-level function in server that should interrupt the current computation and return to the Twelf top-level, not to an ML debugger or the ML top-level. I saw the documentation on signals, but I don't see how to achieve the desired effect because the handler will be run in a different thread.
Any advice or help would be appreciated.
I'm not certain I've understand this exactly but I think maybe the Process.interruptConsoleProcesses function may do what you want. Processes (i.e. threads) are divided into those that receive the SML90.Interrupt exception (console processes) and those that do not. The Interrupt exception is sent to a console process in one of three cases:
- If Process.interruptConsoleProcesses is called all console
processes are interrupted 2. When a process is created using Process.console a function is returned which when called raises Interrupt in that process only. 3. All console processes will receive an Interrrupt exception when ^C is pressed followed by "f", provided the handling of ^C has not been changed using Signal.signal. It is possible to change the handling of ^C so that it raises an interrupt immediately (rather than producing the => prompt) using Signal.signal(2, Signal.SIG_HANDLE(fn _ => Process.interruptConsoleProcesses())); This is what Isabelle does from what I recall.
Regards, David.