Next: , Previous: , Up: Signal handling   [Contents]


7.2 The deferral mechanism

7.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 responsibility 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.

7.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.

7.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.

7.2.4 When are signals handled?

At once or as soon as the mechanism that deferred them allows.

First, if something is deferred by pseudo atomic then it is run at the end of pseudo atomic without exceptions. Even when both a GC request or a SIG_STOP_FOR_GC and a deferrable signal such as SIG_INTERRUPT_THREAD interrupts the pseudo atomic section.

Second, an interrupt deferred by WITHOUT-INTERRUPTS is run when the interrupts are enabled again. GC cannot interfere.

Third, if GC or SIG_STOP_FOR_GC is deferred by WITHOUT-GCING then the GC or stopping for GC will happen when GC is not inhibited anymore. Interrupts cannot delay a gc.


Next: , Previous: , Up: Signal handling   [Contents]