From eb547ca67c6ab282ba805fbb7e19826d32f940a7 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Sat, 30 Jan 2016 18:10:37 -0700 Subject: [PATCH] Fix try-lock-thread-mutex to work when there is no current thread. GC daemons need to run when there is no current thread. Try-lock- thread-mutex was intended for their use. They do not mind occasionally skipping an opportunity to clean, including the rare times when a GC interrupt occurs with no current thread -- in the thread system of a quiescent world. Try-lock-thread-mutex was signaling spurious deadlocks when GC daemons ran with no current thread. Free locks appeared to be owned by #F -- the current thread. --- src/runtime/thread.scm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/runtime/thread.scm b/src/runtime/thread.scm index 442bbd8fb..744a382e6 100644 --- a/src/runtime/thread.scm +++ b/src/runtime/thread.scm @@ -1202,10 +1202,13 @@ USA. (without-interrupts (lambda () (and (not (thread-mutex/owner mutex)) - (let ((thread (current-thread))) - (set-thread-mutex/owner! mutex thread) - (add-thread-mutex! thread mutex) - #t))))) + (let ((thread first-running-thread)) + ;; GC daemons may use this when there is no current thread. + (and thread + (begin + (set-thread-mutex/owner! mutex thread) + (add-thread-mutex! thread mutex) + #t))))))) (define (with-thread-mutex-lock mutex thunk) (guarantee-thread-mutex mutex 'WITH-THREAD-MUTEX-LOCK) -- 2.25.1