Next: , Previous: Groups of signals, Up: Signal handling


6.2 The deferral mechanism

6.2.1 Pseudo atomic sections

Some operations, such as allocation, consist of several steps and temporarily break for instance gc invariants. Interrupting said operations is therefore dangerous to one's health. Blocking the signals for each allocation is out of question as the overhead of the two sigsetmask system calls would be enormous. Instead, pseudo atomic sections are implemented with a simple flag.

When a deferrable signal is delivered to a thread within a pseudo atomic section the pseudo-atomic-interrupted flag is set, the signal and its context are stored, and all deferrable signals blocked. This is to guarantee that there is at most one pending handler in SBCL. While the signals are blocked, the responsibilty of keeping track of other pending signals lies with the OS.

On leaving the pseudo atomic section, the pending handler is run and the signals are unblocked.

6.2.2 WITHOUT-INTERRUPTS

Similar to pseudo atomic, WITHOUT-INTERRUPTS defers deferrable signals in its thread until the end of its body, provided it is not nested in another WITHOUT-INTERRUPTS.

Not so frequently used as pseudo atomic, WITHOUT-INTERRUPTS benefits less from the deferral mechanism.

6.2.3 Stop the world

Something of a special case, a signal that is blockable but not deferrable by WITHOUT-INTERRUPTS is SIG_STOP_FOR_GC. It is deferred by pseudo atomic and WITHOUT-GCING.