lmj / lparallel

Parallelism for Common Lisp
http://lparallel.org
BSD 3-Clause "New" or "Revised" License
242 stars 29 forks source link

END-KERNEL isn't sufficient #50

Closed phmarek closed 8 months ago

phmarek commented 8 months ago

The current implementation of END-KERNEL isn't sufficient - the threads are not necessarily gone when that function returns.

I'm doing something akin to

  (let (...
        (lparallel:*kernel* (lparallel:make-kernel 4)))
    (format t "Loading...~%")
    (lparallel:pmap nil 
                    (lambda (file)
                      (import-file ...))
                    ...)
    (lparallel:end-kernel :wait t))
  (save-lisp-and-die ...)

but that (sometimes) breaks with

debugger invoked on a SB-IMPL::SAVE-WITH-MULTIPLE-THREADS-ERROR in thread
#<THREAD tid=3161136 "main thread" RUNNING {1003848003}>:
  Cannot save core with multiple threads running.

  Interactive thread (of current session):
    #<THREAD tid=3161136 "main thread" RUNNING {1003848003}>

  Other thread:
    #<THREAD "lparallel" FINISHED values: NIL {1069E88B23}>
See also:
  The SBCL Manual, Node "Saving a Core Image"

What does seem to help is to use

    (map 'nil
         #'sb-thread:join-thread
         (lparallel:end-kernel :wait t))))

but I guess that should be done in lparallel proper?!

Thanks!

luismbo commented 8 months ago

Maybe raise the issue at and/or send a pull request to https://github.com/sharplispers/lparallel

phmarek commented 8 months ago

Thanks, will do! This repo is listed on https://lparallel.org/download/, that's how I got here.