1.0.10.51: New function: THREAD-YIELD
authorNIIMI Satoshi <sa2c@users.sourceforge.net>
Sat, 20 Oct 2007 06:27:20 +0000 (06:27 +0000)
committerNIIMI Satoshi <sa2c@users.sourceforge.net>
Sat, 20 Oct 2007 06:27:20 +0000 (06:27 +0000)
An interface to sched_yield().  And use it in busy loops in some tests.

doc/manual/threading.texinfo
package-data-list.lisp-expr
src/code/target-thread.lisp
src/runtime/thread.c
tests/clos-add-remove-method.impure.lisp
tests/clos-cache.impure.lisp
tests/threads.impure.lisp
version.lisp-expr

index 7e84de5..57eaf58 100644 (file)
@@ -43,6 +43,7 @@ threading on Darwin (Mac OS X) and FreeBSD on the x86 is experimental.
 @include fun-sb-thread-interrupt-thread-error-thread.texinfo
 @include fun-sb-thread-interrupt-thread.texinfo
 @include fun-sb-thread-terminate-thread.texinfo
+@include fun-sb-thread-thread-yield.texinfo
 
 @node Special Variables
 @comment  node-name,  next,  previous,  up
index a74cd99..c93e2c4 100644 (file)
@@ -1691,6 +1691,7 @@ is a good idea, but see SB-SYS re. blurring of boundaries."
                "INTERRUPT-THREAD-ERROR"
                "INTERRUPT-THREAD-ERROR-THREAD"
                "INTERRUPT-THREAD" "TERMINATE-THREAD" "DESTROY-THREAD"
+               "THREAD-YIELD"
                "MUTEX" "MAKE-MUTEX" "MUTEX-NAME" "MUTEX-VALUE"
                "GET-MUTEX" "RELEASE-MUTEX" "WITH-MUTEX"
                "WITH-RECURSIVE-LOCK"
index 38549a3..b60ce71 100644 (file)
@@ -844,6 +844,12 @@ SB-EXT:QUIT - the usual cleanup forms will be evaluated"
              (sap-ref-sap thread-sap (* sb!vm:n-word-bytes
                                         sb!vm::thread-next-slot)))))))
 
+(define-alien-routine "thread_yield" int)
+
+#!+sb-doc
+(setf (fdocumentation 'thread-yield 'function)
+      "Yield the processor to other threads.")
+
 #!+sb-thread
 (defun symbol-value-in-thread (symbol thread-sap)
   (let* ((index (sb!vm::symbol-tls-index symbol))
index 9044dfd..d38fd72 100644 (file)
@@ -729,3 +729,13 @@ void gc_start_the_world()
     FSHOW_SIGNAL((stderr,"/gc_start_the_world:end\n"));
 }
 #endif
+
+int
+thread_yield()
+{
+#ifdef LISP_FEATURE_SB_THREAD
+    return sched_yield();
+#else
+    return 0;
+#endif
+}
index 6d09340..b4ac601 100644 (file)
 (defvar *run* nil)
 
 (defun remove-methods (list)
-  (loop until *run*)
+  (loop until *run* do (sb-thread:thread-yield))
   (dolist (method list)
     (remove-method #'foo method)))
 
 (defun add-methods (list)
-  (loop until *run*)
+  (loop until *run* do (sb-thread:thread-yield))
   (dolist (method list)
     (add-method #'foo method)))
 
index 4959a3f..c3e07d6 100644 (file)
@@ -65,7 +65,7 @@
 
 (defun test-loop ()
   (note "/~S waiting for permission to run" sb-thread:*current-thread*)
-  (loop until *run-cache-test*)
+  (loop until *run-cache-test* do (sb-thread:thread-yield))
   (note "/~S joining the thundering herd" sb-thread:*current-thread*)
   (handler-case
       (loop repeat 1024 do (test-cache))
index 867f408..c68b615 100644 (file)
@@ -73,7 +73,8 @@
                (loop repeat 10
                      collect (sb-thread:make-thread
                               (lambda ()
-                                (loop until run)
+                                (loop until run
+                                   do (sb-thread:thread-yield))
                                 (loop repeat n do (,incf x)))))))
          (setf run t)
          (dolist (th threads)
index 02d1ab1..f1a6863 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.10.50"
+"1.0.10.51"