lmj / lparallel

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

Should lparallel threads keep Franz Lisp alive? #11

Closed asmyers closed 10 years ago

asmyers commented 11 years ago

By default when a thread is created in Franz Lisp the image will not exit until the thread does. This behavior can be modified by (setf (mp:process-keeps-lisp-alive-p thread) nil).

The current default behavior of lparallel threads keeping lisp alive inhibits scripting of Lisp which uses lparallel. My workaround is currently:

(let ((old-procs mp:*all-processes*))
  (setf lp:*kernel* (lp:make-kernel 6))
  (loop for thread in (set-difference mp:*all-processes* old-procs)
          do (setf (mp:process-keeps-lisp-alive-p thread) nil)))

There are a bunch of obvious problems with this but it's a hack that works for now. My personal preference for a change to lparallel for this is one of the following, in preferred order:

1) Start threads without the keep alive status. 2) Add some kind of option to make-kernel to disable keep alive status. 3) Provide a high level interface to get the threads in the kernel so I can manually change their keep alive status.

Is there some existing interface for this that I'm missing?

lmj commented 11 years ago

Have you tried end-kernel?

lmj commented 11 years ago

Shall I close this issue? The recommended strategy is to fully control the starting and stopping of kernels, which might include logic for stopping task creation when some condition is met. You also have access to the implementation-defined thread objects via the return value of end-kernel.

asmyers commented 11 years ago

This does work for me so if there is no better API then the issue can be closed. Thanks for the input.

lmj commented 11 years ago

Killing threads should really only be done in exceptional circumstances; the normal code path should gracefully end tasks and kernels. I would argue that this is the better strategy rather than being a workaround for lack of functionality in the lparallel API. But I could be overlooking a case where this is this difficult or too inconvenient. Could you describe your use case?