[slime-devel] auto-flush-thread cleanup and stop-server fix

Sven Van Caekenberghe sven at beta9.be
Tue Dec 9 10:55:40 UTC 2008


Hi,

While trying to use SLIME/SWANK to repeatedly connect/disconnect to/ 
from a remote long running server image I encountered some problems  
that I tried to fix. The server image is LispWorks 5.1.1 on Intel  
(Linux & Mac OS X), the client is Emacs 23 on Mac OS X 10.5.5 Intel,  
SLIME/SWANK the current CVS head.

The first problem is that, in my situation, when running SWANK  
manually with (swank:create-server :dont-close t) and connecting/ 
disconnecting manually from SLIME, the auto-flush-thread was not  
cleaned up. Doing this multiple times gave me multiple defunct auto- 
flush-threads. Maybe this only happens on LispWorks, I don't know.

I fixed this by adding an auto-flush-thread slot to the connect  
structure, setting this slot to the auto-flush-thread in open-streams  
and finally adding it to the thread list in cleanup-connection- 
threads. This seems to fix my problem in my situation. Is this an  
acceptable patch ?

Also, calling stop-server with an integer port number didn't work. The  
problem was that list-threads returns the thread/process name in  
second position and not in first position (where the ID is).

I included a diff below. If you want the patch any other way, just ask.

HTH,

Sven

--
Sven Van Caekenberghe - mailto:sven at beta9.be
Beta Nine - software engineering - http://www.beta9.be
.Mac - svc at mac.com - http://homepage.mac.com/svc

"Lisp isn't a language, it's a building material." - Alan Kay


[sven at voyager:~/apps/slime]$ cvs diff -u swank.lisp
Index: swank.lisp
===================================================================
RCS file: /project/slime/cvsroot/slime/swank.lisp,v
retrieving revision 1.612
diff -u -r1.612 swank.lisp
--- swank.lisp	9 Dec 2008 07:48:20 -0000	1.612
+++ swank.lisp	9 Dec 2008 10:48:08 -0000
@@ -241,6 +241,7 @@
    reader-thread
    control-thread
    repl-thread
+  auto-flush-thread
    ;; Callback functions:
    ;; (SERVE-REQUESTS <this-connection>) serves all pending requests
    ;; from Emacs.
@@ -762,7 +763,7 @@
         (let ((thread-position
                (position-if
                 (lambda (x)
-                 (string-equal (first x)
+                 (string-equal (second x)
                                 (concatenate 'string "Swank "
                                              (princ-to-string port))))
                 (list-threads))))
@@ -865,8 +866,9 @@
           (repl-results (make-output-stream-for-target connection
                                                        :repl-result)))
      (when (eq (connection.communication-style connection) :spawn)
-      (spawn (lambda () (auto-flush-loop out))
-             :name "auto-flush-thread"))
+      (setf (connection.auto-flush-thread connection)
+            (spawn (lambda () (auto-flush-loop out))
+                   :name "auto-flush-thread")))
      (values dedicated-output in out io repl-results)))

  ;; FIXME: if wait-for-event aborts the event will stay in the queue  
forever.
@@ -1197,7 +1199,8 @@
  (defun cleanup-connection-threads (connection)
    (let ((threads (list (connection.repl-thread connection)
                         (connection.reader-thread connection)
-                       (connection.control-thread connection))))
+                       (connection.control-thread connection)
+                       (connection.auto-flush-thread connection))))
      (dolist (thread threads)
        (when (and thread
                   (thread-alive-p thread)





More information about the slime-devel mailing list