From: Matt Birkholz Date: Sun, 31 Jan 2016 01:10:37 +0000 (-0700) Subject: Fix try-lock-thread-mutex to work when there is no current thread. X-Git-Tag: mit-scheme-pucked-9.2.12~371^2~4 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=eb547ca67c6ab282ba805fbb7e19826d32f940a7;p=mit-scheme.git 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. --- 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)