[Mono-dev] Control-C handler
jonpryor at vt.edu
Thu Dec 20 14:41:45 EST 2007
On Thu, 2007-12-20 at 14:16 -0500, Miguel de Icaza wrote:
> > You can use signal(2), which is helpfully exposed by Mono.Posix.dll.
> > See the attached program.
> This actually would corrupt the application state, because the C-c
> handler will run the entire JIT at that point and this happens in the
> same thread as the executing thread.
Isn't there a method that says "JIT this function now"? (I thought
Marshal.Prelink() did that, which is what Stdlib.signal() calls, but I
just re-read the documentation and it doesn't do anything of the sort.)
Before dropping to C, though, there are two alternatives:
1. Call handler() *before* passing it to Stdlib.signal():
Stdlib.signal (Signum.SIGINT, handler);
/* ... as before ... */
This would require changing handler() to know about this initialization
call and NOT set ctrl_c_pressed if the parameter is -1.
This would also allow a pure C# signal handler, as the method will be
JITed during the first handler() call.
2. Use System.Runtime.ConstrainedExecution.PrePrepareMethodAttribute on
the signal handler method. This would require that Mono have support
for Constrained Execution regions, which I believe is currently lacking,
but would presumably eventually be supported.
More information about the Mono-devel-list