From ac8c28ab97ce2ed60b636677a88c7bc496ae4f43 Mon Sep 17 00:00:00 2001 From: Jan Moringen Date: Fri, 28 Apr 2017 13:21:37 +0200 Subject: [PATCH] Fix RELEASE-FOREGROUND in case of "dead" thread as NEXT argument Calling RELEASE-FOREGROUND with an already dead thread as next argument previously made the dead thread the foreground thread. At that point, all succeeding GET-FOREGROUND calls would just hang. --- src/code/target-thread.lisp | 2 +- tests/session.impure.lisp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/code/target-thread.lisp b/src/code/target-thread.lisp index c60123c68..50e830eba 100644 --- a/src/code/target-thread.lisp +++ b/src/code/target-thread.lisp @@ -1358,7 +1358,7 @@ have the foreground next." ((interactive-threads (session-interactive-threads session))) (setf interactive-threads (delete *current-thread* interactive-threads)) - (when next + (when (and next (thread-alive-p next)) (setf interactive-threads (list* next (delete next interactive-threads)))) (condition-broadcast (session-interactive-threads-queue session)))))) diff --git a/tests/session.impure.lisp b/tests/session.impure.lisp index 501412d3d..81b4361bf 100644 --- a/tests/session.impure.lisp +++ b/tests/session.impure.lisp @@ -110,3 +110,14 @@ :name "get-foreground hang missing-broadcast test"))) (sb-thread:release-foreground thread) (get-foreground-quietly))) + +;;; Releasing foreground to an already dead thread previously made the +;;; dead thread the foreground thread. At that point, all succeeding +;;; GET-FOREGROUND calls would just hang. +(with-test (:name (sb-thread::get-foreground :hang :already-dead)) + (let ((thread (sb-thread:make-thread + (lambda ()) + :name "get-foreground hang already-dead test"))) + (sb-thread:join-thread thread) + (sb-thread:release-foreground thread) + (get-foreground-quietly))) -- 2.11.4.GIT