[Mono-dev] Control-C handler

Jonathan Pryor jonpryor at vt.edu
Tue Jan 8 22:02:35 EST 2008

Thank you for the background on why signal handlers can't be made to
work with the current Stdlib.signal implementation.


On Tue, 2008-01-08 at 21:17 +0100, Paolo Molaro wrote:
> All of this can be easily overcome with a sane interface for signals
> provided by Mono.Posix (the implementation can be in either the helper
> lib or in the runtime).
> This would export a class like (pseudo code):
> 	class UnixSignalHandler {
> 		IntPtr flag_var_ptr;
> 		pulic UnixSignalHandler (int signal) {
> 			flag_var_ptr = Install (signal);
> 			if (flag_var_ptr == null)
> 				throw new Exception ();
> 		}
> 		~UnixSignalHandler () {
> 			Uninstall (signal, flag_var_ptr);
> 		}
> 		public bool IsSignalled {
> 			get {
> 				if (*(int*)flag_var_ptr) {
> 					*(int*)flag_var_ptr = 0;
> 					return true;
> 				}
> 				return false;
> 			}
> 		}
> 	}

I don't see why we need a new API to support this.  It seems that we
could retrofit the existing Stdlib.signal() API to use the
implementation you described, with one difference: a runtime internal
thread could be used to block on the internal pipe, and when the pipe is
readable it could dispatch the appropriate signal via delegate
registered with Stdlib.signal().  No polling, and no new public API
would be required.

The one thing I'm not sure about is which thread should wait on the
pipe.  Would a dedicated Mono.Posix-internal thread be more appropriate,
or would one of the existing threads be beter (e.g. a ThreadPool thread,
or a Timer-related thread, or...).


 - Jon

More information about the Mono-devel-list mailing list