Fix try-lock-thread-mutex to work when there is no current thread.
authorMatt Birkholz <puck@birchwood-abbey.net>
Sun, 31 Jan 2016 01:10:37 +0000 (18:10 -0700)
committerMatt Birkholz <puck@birchwood-abbey.net>
Wed, 3 Feb 2016 00:08:15 +0000 (17:08 -0700)
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

index 442bbd8fb3d311e76d791ac643ef386e016fba23..744a382e6011202f0450ccb35e8fcc3db6bc27d4 100644 (file)
@@ -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)))))))
 \f
 (define (with-thread-mutex-lock mutex thunk)
   (guarantee-thread-mutex mutex 'WITH-THREAD-MUTEX-LOCK)