1.0.17.2: better PRINT-OBJECT method for threads
authorNikodemus Siivola <nikodemus@random-state.net>
Wed, 28 May 2008 16:00:35 +0000 (16:00 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Wed, 28 May 2008 16:00:35 +0000 (16:00 +0000)
 * In addition to name, if any, print current state (RUNNING, ABORTED, or
   FINISHED), and any values returned by the thread if it has finished.

src/code/target-thread.lisp
version.lisp-expr

index 1ddd0a1..547ee99 100644 (file)
@@ -39,14 +39,22 @@ in future versions."
       "The name of the thread. Setfable.")
 
 (def!method print-object ((thread thread) stream)
-  (if (thread-name thread)
-      (print-unreadable-object (thread stream :type t :identity t)
-        (prin1 (thread-name thread) stream))
-      (print-unreadable-object (thread stream :type t :identity t)
-        ;; body is empty => there is only one space between type and
-        ;; identity
-        ))
-  thread)
+  (print-unreadable-object (thread stream :type t :identity t)
+    (let* ((cookie (list thread))
+           (info (if (thread-alive-p thread)
+                     :running
+                     (multiple-value-list (join-thread thread :default cookie))))
+           (state (if (eq :running info)
+                      info
+                      (if (eq cookie (car info))
+                          :aborted
+                          :finished)))
+           (values (when (eq :finished state) info)))
+      (format stream "~@[~S ~]~:[~A~;~A~:[ no values~; values: ~:*~{~S~^, ~}~]~]"
+              (thread-name thread)
+              (eq :finished state)
+              state
+              values))))
 
 (defun thread-alive-p (thread)
   #!+sb-doc
index 7b6d9ef..f71279f 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.17.1"
+"1.0.17.2"