[Openmcl-devel] SOLVED: Was Garbage collector - ccl:terminate (memory stuff)

R. Matthew Emerson rme at clozure.com
Fri May 31 11:33:15 PDT 2024



> On May 22, 2024, at 2:22 PM, Grégory Vanuxem <g.vanuxem at gmail.com> wrote:
> 
> Hi Robert, hi all,
> 
> Many thanks for your reply. It allowed me to go further into this and
> I have found a solution.
> 
> In the FriCAS context, the email, I just sent to the FriCAS mailing list:
> https://groups.google.com/g/fricas-devel/c/kHMffXyMIB0/m/hMh1mMasBQAJ
> 
> Basically FriCAS create a simple fricas-class application:
> 
> (defclass fricas-application (ccl::application) ())

It looks a bit odd that you are inheriting from ccl::application here, yet in your toplevel-function method below, you create an instance of ccl::lisp-development-system.  I’m somewhat surprised that works for you.

> 
> and use it at startup:
> 
> (defmethod ccl::toplevel-function ((app fricas-application) init-file)
> [snippet]
>        (funcall *my-toplevel-function*)
>        (let ((ap (make-instance 'ccl::lisp-development-system)))
>            (ccl::toplevel-function ap init-file)))
> 
> And, basically, the fricas-application (FiCAS) when
> 
>       (CCL::save-application core-image
>                                      :PREPEND-KERNEL t
>                                      :application-class 'fricas-application)
> 
> Does not execute ccl:terminate, you have to return (start) to the
> "main" thead/process to allow CCL to execute the terminate method.

What does *my-toplevel-function* do?  If it’s just some additional initialization, maybe you could put a :before method on toplevel-function (application t) instead?

In the method toplevel-function (ccl::lisp-development-system t)

https://github.com/Clozure/ccl/blob/19906f6afdff4dbf232f560a4d13a81da65daf5f/level-1/l1-application.lisp#L284

we start a loop that calls the function called ccl::housekeeping a few times a second.  One of the housekeeping tasks is to run gc hook functions.  (The hook functions are managed via ccl::add-gc-hook and ccl::remove-gc-hook.)

https://github.com/Clozure/ccl/blob/19906f6afdff4dbf232f560a4d13a81da65daf5f/level-1/l1-events.lisp#L166

As you may suspect by now, the way termination functions get called is via a gc hook. So, if the housekeeping loop doesn’t run for some reason, then automatic termination won’t work.

If you can’t run the housekeeping loop, I think it would work to call ccl:drain-termination-queue manually as needed.



> 
> Removing the need of a specific class for Clozure CL, FriCAS built
> with other CL implementations does not use a specific class, allowed
> me to solve my problem. But a question remains: why, after a
> save-application, and running directly at startup the above method,
> fricas can not use ccl:::terminate, apparently only the "main" thread
> is allowed to do that?
> 
> Thanks all!
> 
> - Greg
> 
> PS: the diff when saving FriCAS application
> 
>          (top-fun #'(lambda ()
>                        (set-initial-parameters)
> -                       (funcall restart-fun))))
> +                       (funcall restart-fun)
> +                       (ccl::toplevel-loop))))
>         (setf *ccl-default-directory* ccl-dir)
> -        (setf *my-toplevel-function* top-fun)
> -        (CCL::save-application core-image
> -                                       :PREPEND-KERNEL t
> -                                       :application-class 'fricas-application)
> +        (CCL::save-application core-image :toplevel-function top-fun
> +                                       :PREPEND-KERNEL t)
>         (QUIT))
> 




More information about the Openmcl-devel mailing list