Chapter 7. Signals and interrupts

7.1. Problems associated to signals
7.2. Kinds of signals
7.2.1. Synchronous signals
7.2.2. Asynchronous signals
7.3. Signals and interrupts in ECL
7.3.1. Handling of asynchronous signals
7.3.2. Handling of synchronous signals
7.4. Considerations when embedding ECL
7.5. Signals Reference
ext:with-interrupts — Execute code with interrupts optionally enabled.
ext:without-interrupts — Execute code without being interrupted.

7.1. Problems associated to signals

POSIX contemplates the notion of "signals", which are events that cause a process or a thread to be interrupted. Windows uses the term "exception", which includes also a more general kind of errors.

In both cases the consequence is that a thread or process may be interrupted at any time, either by causes which are intrinsic to them (synchronous signals), such as floating point exceptions, or extrinsic (asynchronous signals), such as the process being aborted by the user.

Of course, those interruptions are not always welcome. When the interrupt is delivered and a handler is invoked, the thread or even the whole program may be in an inconsistent state. For instance the thread may have acquired a lock, or it may be in the process of filling the fields of a structure. Furthermore, sometimes the signal that a process receives may not even be related to it, as in the case when a user presses Cltr-C and a SIGINT signal is delivered to an arbitrary thread, or when the process receives the Windows exception CTRL_CLOSE_EVENT denoting that the terminal window is being closed.

Understanding this, POSIX restricts severely what functions can be called from a signal handler, thereby limiting its usefulness. However, Common Lisp users expect to be able to handle floating point exceptions and to gracefully manage user interrupts, program exits, etc. In an attempt to solve this seemingly impossible problem, ECL has taken a pragmatic approach that works, it is rather safe, but involves some work on the ECL maintainers and also on users that want to embed ECL as a library.