[slime-cvs] CVS slime

CVS User nsiivola nsiivola at common-lisp.net
Fri Apr 20 12:45:28 UTC 2012


Update of /project/slime/cvsroot/slime
In directory tiger.common-lisp.net:/tmp/cvs-serv15282

Modified Files:
	ChangeLog swank-sbcl.lisp 
Log Message:
sbcl: workaround for auto-flush thread deadlocks, take II

  Occasionally auto-flush thread could deadlock with a thread doing
  compilation:

    T1: grabs world-lock
    T2: decides to flush, grabs stream lock
    T1: needs to do output (compiler note, etc), waits on the stream lock
    T2: needs the world-lock for a while (PCL dispatch machinery setup, etc)

    *boink*

  This is an SBCL issue, no mistake about it -- but sorting out the world-lock
  handling is going to take a while, and sticking a deadline around the
  FINISH-OUTPUT call avoids the issue.

  In this iteration the change is limited to swank-sbcl.lisp, making it
  hopefully non-intrusive enough to stay in.


--- /project/slime/cvsroot/slime/ChangeLog	2012/04/20 12:43:04	1.2317
+++ /project/slime/cvsroot/slime/ChangeLog	2012/04/20 12:45:28	1.2318
@@ -1,5 +1,13 @@
 2012-04-20  Nikodemus Siivola  <nikodemus at random-state.net>
 
+	* swank-sbcl.lisp (stream-force-output :around): Workaroud for
+	deadlocks between auto-flush-thread buffer write lock and world
+	lock.
+	(slime-output-stream): Dummy forward definition for the benefit of
+	the defmethod.
+
+2012-04-20  Nikodemus Siivola  <nikodemus at random-state.net>
+
 	* swank-sbcl.lisp (swank-value): New function, makes it easy to
 	refer to variables in SWANK -- which doesn't exist when the
 	backend is loaded.
--- /project/slime/cvsroot/slime/swank-sbcl.lisp	2012/04/20 12:43:04	1.307
+++ /project/slime/cvsroot/slime/swank-sbcl.lisp	2012/04/20 12:45:28	1.308
@@ -17,15 +17,14 @@
   (require 'sb-bsd-sockets)
   (require 'sb-introspect)
   (require 'sb-posix)
-  (require 'sb-cltl2))
+  (require 'sb-cltl2)
+  (import-from :sb-gray *gray-stream-symbols* :swank-backend))
 
 (declaim (optimize (debug 2) 
                    (sb-c::insert-step-conditions 0)
                    (sb-c::insert-debug-catch 0)
                    (sb-c::merge-tail-calls 2)))
 
-(import-from :sb-gray *gray-stream-symbols* :swank-backend)
-
 ;;; backwards compability tests
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
@@ -1634,6 +1633,26 @@
       (sb-thread:with-mutex (mutex) 
         (cdr (assoc name alist)))))
 
+  ;; Workaround for deadlocks between the world-lock and auto-flush-thread
+  ;; buffer write lock.
+  ;;
+  ;; Another alternative would be to grab the world-lock here, but that's less
+  ;; future-proof, and could introduce other lock-ordering issues in the
+  ;; future.
+  ;;
+  ;; In an ideal world we would just have an :AROUND method on
+  ;; SLIME-OUTPUT-STREAM, and be done, but that class doesn't exist when this
+  ;; file is loaded -- so first we need a dummy definition that will be
+  ;; overridden by swank-gray.lisp.
+  (defclass slime-output-stream (fundamental-character-output-stream)
+    ())
+  (defmethod stream-force-output :around ((stream slime-output-stream))
+    (handler-case
+        (sb-sys:with-deadline (:seconds 0.1)
+          (call-next-method))
+      (sb-sys:deadline-timeout ()
+        nil)))
+
   )
 
 (defimplementation quit-lisp ()





More information about the slime-cvs mailing list