On Wed, Dec 10, 2008 at 10:32 PM, <wagwilk@...> wrote:
> Yep, I found out where the progv, its in my prolog escape back-to-lisp
> function, 'is', and it does bind fresh gensymmed variables.
>
> Does that mean that these special variables are not reclaimed by the system
> when we exit the progv?
Yes and no. The gensyms get collected, but the thread-local binding
storage that has been reserved cannot be reclaimed: each symbol that
has a special variable binding gets a thread local storage index.
Since these indexes increase monotonically, we cannot reuse ones
allocated to symbols that have later become garbage. (I consider this
a bug, the fix is known, and means switching to "wide-binding" style
along the lines of what Allegro does.)
For now, the way around this looks something like this:
(defvar *free-gensyms* nil)
(defvar *free-gensym-lock* (sb-thread:make-mutex :name "Free Gensym Lock"))
(defmacro with-temp-gensym ((var) &body)
`(let ((,var (sb-thread:with-mutex (*free-gensym-lock*)
(or (pop *free-gensyms*)
(gensym (string ',var))))))
(unwind-protect
(locally ,@body)
(sb-thread:with-mutex (*free-gensym-lock*)
(push ,var *free-gensyms*)))))
and using WITH-TEMP-GENSYM instead of GENSYM to allocate the PROGV
bound gensyms.
Cheers,
-- Nikodemus
|