Subject: [clisp-list] howto: Finalization in CLISP

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Fri Jul 19 07:18:38 2002

Sam asked:
>>this is easy to fix - just run all finalizers on exit.  should it be?
>>what are the issues?  (obviously, the possible errors while running
>>the finalizers have to be ignored -- what else?)

>o Finalizers which do nothing more than free() or 
>close[socket]() are superfluous and waste precious time when 
>an application has been ordered to exit. I.e. all finalizers 
>for resources which the OS closes itself upon program exit.

From my own experience with modules, I'd say that a module exit function is what I'm missing, not finalization for every resource obtained via the library. And perhaps some dependency mechanism would be useful as well. The reason is that shared libraries mostly do resource tracking themselves.
I.e., I believe I don't need to close all sockets before closing the socket library. Therefore, when shutting down, it's advantageous not to pedantically close single resources when they can go away in one go (e.g. don't do thousands of 8byte frees when one sbrk() or free_pool_for_tiny_mallocs() is enough).

However, my experience may be biased by the fact that I wrote all modules by hand, i.e. I wrote C code. People who use the FFI to define interface stubs to existing libraries may rightly wish to achieve this without writing C code.

Maybe this is just a matter of having Lisp-level functions like MARK-INVALID-FOREIGN to to the kind of things in Lisp I so far preferred to do in C.
Maybe not.

The previously mentioned issue of whether it's acceptable to run arbitrary user code after EXT/SYS:EXIT has been called comes to mind again. Combined with the issue of what (possibly corrupt) state the Lisp system may be in when EXIT is invoked by Lisp code, or by CLISP itself.

Regards,
	Jorg Hohle.