Save a CL image without exiting the environment

371 views Asked by At

I want to save a "snapshot" of the current environment so I can play with it later without consequences for messing it up. (Essentially creating a sandbox)

I know that I can save the image with (save-lisp-and-die "sbcl.core"). I also know that I can then load the image with sbcl --core sbcl.core.

The problem is that I have running threads that I cannot afford to stop even for a second and this command will exit sbcl.

My question is: Can I create an image without exiting the environment? I am looking for something like (save-lisp "sbcl.core")

If there is a portable way to do that - it would be great. If not - I am interested in a solution for SBCL.

1

There are 1 answers

1
coredump On BEST ANSWER

SBCL core saving gives the following function, based on SBCL manual's advice:

(defun save-core (core-fn)
  (progn
    #+sbcl
    (let ((fork-result (sb-posix:fork)))
      (case fork-result
        (-1 (error "fork failed"))
        (0 (sb-ext:save-lisp-and-die core-fn :toplevel #'main :executable t))
        (otherwise (sb-posix:wait)))
      (format t "stand-alone core ~a saved" core-fn))
    #-sbcl
    (error "not available on this lisp")
    (values)))

Unfortunately it might not work with running threads.