[Openmcl-devel] Unix signal handling

Gary Byers gb at clozure.com
Tue Jul 6 03:46:54 UTC 2010



On Mon, 5 Jul 2010, Scott L. Burson wrote:

> Hi,
> 
> I am porting a large, old application from Allegro to Clozure.  The app runs
> under Emacs -- it has its own code, on both the Emacs and Lisp sides, for
> doing this -- and Emacs sometimes gets the Lisp process's attention by
> sending it a Unix signal (normally SIGUSR1 or SIGUSR2, but this is
> configurable).
> 
> Allegro provides a relatively straightforward way to set up a Lisp function
> to be called when a signal is received, but I don't see anything like that
> in CCL.  Have I just overlooked it?  If not, how hard would it be to create?

There isn't any general way of defining signal handlers in CCL.  The issue
comes up every few months on this list, and the response is usually "yeah,
we should offer that.  Someday."  It's almost certainly doable, but there are
threads/GC issues that make the implementation complicated.

Additionally, the implementation of things like PROCESS-INTERRUPT and the
mechanism that the GC uses to suspend/resume other threads involves sending
signals between threads; on some platforms (Darwin), the implementation uses
SIGUSR1 and SIGUSR2 and possibly something else that the OS never raises, and
it's not clear that there are any leftover unused signal numbers ...

It might be tempting to just do:

(defcallback my-signal-handler (:int signo :void)
   (some-code-that-can-run-at-interrupt-time))

(#_signal #$some-signal my-signal-handler)

and that'd work some of the time.  It'd fail (subtly or spectacularly) if the
GC ran in some other thread and that signal handler interrupted some lisp code.
(The GC would likely not be able to see the lisp object references that that
interrupted code was making, and things would go downhill from there.)  There
are some other issues there, so any viable mechanism would have to deal with
those issues around a call to your code.


> 
> Alternatives exist, of course -- I could set up another stream with a Lisp
> thread reading from it, and just send a character on the stream.  Sounds
> like a bit of work, though I haven't looked into it; not sure if Emacs will
> cooperate.  Anyway I wanted to explore the signal handling approach first,
> since that is how it works with Allegro.
> 
> Any advice?
> 
> -- Scott
> 
> 
>


More information about the Openmcl-devel mailing list