[Openmcl-devel] add-gc-hook / drain-termination-queue
carlos.ungil at gmail.com
Thu Sep 5 19:39:18 CDT 2013
to ensure that finalizers are run from the main thread, I'm doing the
(setq ccl:*enable-automatic-termination* nil)
(let ((process ccl:*current-process*))
(ccl:process-interrupt process #'ccl:drain-termination-queue)))
Is this a good idea? The fact that add-gc-hook is not exported makes me
The context is the following: RCL embeds R in Common Lisp (using CFFI, the
rf-protect and rf-unprotect-ptr functions below are foreign functions).
When I need to hold a foreign pointer in the lisp side I wrap it in an
object: I "protect" it to prevent it from being garbage-collected in the R
side and I set up a finalizer to "unprotect" it when it's no longer in use.
(defun make-r-pointer (ptr)
(let ((r-pointer (make-instance 'r-pointer :pointer ptr)))
(trivial-garbage:finalize r-pointer (lambda () (rf-unprotect-ptr ptr)))
However, a function triggering garbage collection like the following one
crashes the program (because the protect and unprotect functions will run
concurrently, I think).
(reduce #'+ (loop repeat 10000 append (rcl:r "runif" 1)))
The workaround mentioned above seems to solve the problem, but I wonder if
there might be some undesirable effects.
I also tried to let the automatic termination enabled, forcing the
finalizer to run each time from the main thread
(trivial-garbage:finalize r-pointer (let
((process ccl:*current-process*)) (lambda () (process-interrupt process
but I couldn't make it work (the program hangs).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Openmcl-devel