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

Grégory Vanuxem g.vanuxem at gmail.com
Wed May 22 14:22:32 PDT 2024


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) ())

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.

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))







Le lun. 20 mai 2024 à 11:43, Robert Munyer <2420506348 at munyer.com> a écrit :
>
> While I was waking up, I had a strange thought (possibly left
> over from a dream) about a way to implement a counter that lives
> in "unreachable" heapspace, and is repeatedly destroyed by the
> garbage collector, but continues counting anyway.
>
> Code:
>
>   (defclass garbage-counter () ((n :initarg :n)))
>
>   (defmethod initialize-instance :after
>       ((x garbage-counter) &rest initargs)
>     (declare (ignore initargs))
>     (ccl:terminate-when-unreachable x))
>
>   (let ((s *terminal-io*))
>     (defmethod ccl:terminate ((x garbage-counter))
>       (let ((n (1+ (slot-value x 'n))))
>         (make-instance 'garbage-counter :n n)
>         (format s "~&garbage-counter: ~s~%" n)
>         (finish-output s))))
>
> Usage example:
>
>   ? (progn (make-instance 'garbage-counter :n 0) t)
>   T
>   ? (ccl:gc)
>   NIL
>   ?
>   garbage-counter: 1
>   (ccl:gc)
>   NIL
>   ?
>   garbage-counter: 2
>
> Greg, I had no difficulty getting this to work in FriCAS's "BOOT"
> package; it worked on the first try.  I'll attach a transcript,
> in case seeing exactly what I did might be useful to you.
>


More information about the Openmcl-devel mailing list