[imp-hackers] cl-ext:exit

Brian Mastenbrook brian at mastenbrook.net
Thu Jul 2 15:30:23 UTC 2009


On Jul 2, 2009, at 9:32 AM, Sam Steingold wrote:

> On Thu, Jul 2, 2009 at 2:32 AM, Juan Jose
> Garcia-Ripoll<juanjose.garciaripoll at googlemail.com> wrote:
>> Could we introduce also the notion of "finalizers" or things to be
>> done before exiting, perhaps in the form of a special variable with a
>> list of handlers? QUIT then would have to take an additional option,
>> deciding whether to honor or not those handlers.
>
> http://clisp.podval.org/impnotes/custom-init-fini.html#fini-hooks
>
> 31.1.3. Customizing Termination
>
> CUSTOM:*FINI-HOOKS* is run like this:
>
> (MAPC #'FUNCALL CUSTOM:*FINI-HOOKS*)


SBCL's interface is very similar:

http://www.sbcl.org/manual/Initialization-and-Exit-Hooks.html

— Variable: sb-ext:*exit-hooks*
This is a list of functions which are called in an unspecified order  
when sbcl process exits. Unused by sbcl itself: reserved for user and  
applications. Using (QUIT :recklessly-p T), or calling exit(3)  
directly will circumvent these hooks.

Two things strike me about this documentation: SBCL leaves the order  
of calling unspecified, where CLISP defines an order. I'm not sure why  
the order is unspecified in the documentation; the actual order is the  
same as CLISP. The second is that SBCL's documentation doesn't seem to  
allow for function designators on the list, though they're actually  
allowed. I think the issues here are just documentation issues.

As an implementation matter, SBCL will catch all serious conditions  
thrown by exit hooks and, after unwinding, issue a continuable error  
with one restart, which moves on to the next hook. SBCL also unwinds  
the stack before running exit hooks, so that attempts to invoke a non- 
local transfer of control will fail.

I think that, if this interface or one similar to it were to be  
standardized, we might want to change and extend it a little. I think  
there are actually three levels of "recklessness" of exit that should  
be supported. The non-reckless exit mode runs each exit hook in an  
environment where additional restarts are bound to skip to the next  
hook while keeping or switching the current recklessness mode. This  
would change SBCL's current behavior to not unwind when an serious  
condition is issued in an exit hook by default. A partly-reckless mode  
would run the exit hooks with a handler for errors that immediately  
moves on to the next hook. A truly reckless exit would attempt to exit  
with "all due haste", cutting whatever corners are necessary to  
terminate the current session as soon as possible, including skipping  
all hooks and not invoking any unwind-protect cleanup forms.
--
Brian Mastenbrook
brian at mastenbrook.net
http://brian.mastenbrook.net/





More information about the implementation-hackers mailing list