X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fthreads.impure.lisp;h=c68b61518da484e4fe9ebcd79245da81760d058f;hb=87cd7d9848d9beddbf74e9d56a0c0aea6e189ead;hp=068d68b99a5c02525d88f41c7e0fb7e5c078d79c;hpb=5759fa78f2289c7e891aaded2a54e069b8bdac01;p=sbcl.git diff --git a/tests/threads.impure.lisp b/tests/threads.impure.lisp index 068d68b..c68b615 100644 --- a/tests/threads.impure.lisp +++ b/tests/threads.impure.lisp @@ -13,6 +13,36 @@ (in-package "SB-THREAD") ; this is white-box testing, really +(use-package :test-util) +(use-package "ASSERTOID") + +(setf sb-unix::*on-dangerous-select* :error) + +(defun wait-for-threads (threads) + (mapc (lambda (thread) (sb-thread:join-thread thread :default nil)) threads) + (assert (not (some #'sb-thread:thread-alive-p threads)))) + +(assert (eql 1 (length (list-all-threads)))) + +(assert (eq *current-thread* + (find (thread-name *current-thread*) (list-all-threads) + :key #'thread-name :test #'equal))) + +(assert (thread-alive-p *current-thread*)) + +(let ((a 0)) + (interrupt-thread *current-thread* (lambda () (setq a 1))) + (assert (eql a 1))) + +(let ((spinlock (make-spinlock))) + (with-spinlock (spinlock))) + +(let ((mutex (make-mutex))) + (with-mutex (mutex) + mutex)) + +#-sb-thread (sb-ext:quit :unix-status 104) + ;;; compare-and-swap (defmacro defincf (name accessor &rest args) @@ -43,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) @@ -64,36 +95,6 @@ (svref x 1))) (format t "~&compare-and-swap tests done~%") -(use-package :test-util) -(use-package "ASSERTOID") - -(setf sb-unix::*on-dangerous-select* :error) - -(defun wait-for-threads (threads) - (mapc (lambda (thread) (sb-thread:join-thread thread :default nil)) threads) - (assert (not (some #'sb-thread:thread-alive-p threads)))) - -(assert (eql 1 (length (list-all-threads)))) - -(assert (eq *current-thread* - (find (thread-name *current-thread*) (list-all-threads) - :key #'thread-name :test #'equal))) - -(assert (thread-alive-p *current-thread*)) - -(let ((a 0)) - (interrupt-thread *current-thread* (lambda () (setq a 1))) - (assert (eql a 1))) - -(let ((spinlock (make-spinlock))) - (with-spinlock (spinlock))) - -(let ((mutex (make-mutex))) - (with-mutex (mutex) - mutex)) - -#-sb-thread (sb-ext:quit :unix-status 104) - (let ((old-threads (list-all-threads)) (thread (make-thread (lambda () (assert (find *current-thread* *all-threads*))