[armedbear-devel] destroy-thread and unwind-protect

Alessio Stalla alessiostalla at gmail.com
Mon Oct 24 21:34:24 UTC 2011


On Sun, Oct 23, 2011 at 8:05 PM, James Lawrence <llmjjmll at gmail.com> wrote:
>    (defun test-cleanup ()
>      (let* ((cleanedp nil)
>             (thread (threads:make-thread
>                      (lambda ()
>                        (unwind-protect (sleep 999)
>                          (setf cleanedp t))))))
>        (sleep 0.5)
>        (threads:destroy-thread thread)
>        (sleep 0.5)
>        cleanedp))
>
>    (test-cleanup)
>
> ABCL-1.0.0 and ABCL-0.27.0 return NIL.
>
> Other implementations I tested all return T -- Allegro, Clozure,
> LispWorks, SBCL (changing "threads" to "bordeaux-threads").
>
> Of course this isn't a bug since ABCL is free to do what it wishes.
> Does ABCL wish that?

I don't think we should wish that. It's inconsistent not only with
other Lisp implementations, but with Java thread semantics as well.
The problems are two: first, that destroy-thread doesn't really
destroy the thread, it just sets a flag, so the sleep is not aborted
(when it ends, the next form is not evaluated and the thread just
terminates); second, that sleep swallows the ThreadInterrupted
exception anyway, so even if it were interrupted, the thread would
then continue normally.
I think thread-destroy should be reimplemented to call
Thread.interrupt() and that we should properly handle
InterruptedException as a Lisp condition.




More information about the armedbear-devel mailing list