File tree Expand file tree Collapse file tree 4 files changed +17
-16
lines changed
contrib/sb-concurrency/tests Expand file tree Collapse file tree 4 files changed +17
-16
lines changed Original file line number Diff line number Diff line change 2626 (a 0 )
2727 (b 0 )
2828 (c 0 )
29- (run! nil )
29+ (run! ( sb-thread :make-semaphore) )
3030 (w-e! (cons :write-oops nil ))
3131 (r-e! (cons :read-oops nil )))
3232 (flet ((maybe-pause (pause &optional value)
4141 collect
4242 (make-thread
4343 (lambda ()
44- (loop until run! do (thread-yield) )
44+ (sb-thread :wait-on-semaphore run!)
4545 (handler-case
4646 (loop repeat read-count
4747 do (multiple-value-bind (a b c)
5656 (loop repeat writer-count
5757 collect (make-thread
5858 (lambda ()
59- (loop until run! do (thread-yield) )
59+ (sb-thread :wait-on-semaphore run!)
6060 (handler-case
6161 (loop repeat write-count
6262 do (frlock-write (rw)
7676 (error (e)
7777 (sb-ext :atomic-update (cdr w-e!) #' cons e))))))
7878 (progn
79- (setf run! t )
79+ (sb-thread :signal-semaphore run! ( + reader-count writer-count) )
8080 nil ))))
8181 (values (cdr w-e!) (cdr r-e!))))
8282
Original file line number Diff line number Diff line change 129129 ,@ (to-add ' f))))
130130 (def))
131131
132- (defvar *run* nil )
132+ (defvar *run* ( sb-thread :make-semaphore) )
133133
134134(defun remove-methods (list )
135- (loop until *run* do ( sb-thread :thread-yield) )
135+ (sb-thread :wait-on-semaphore *run* )
136136 (dolist (method list )
137137 (remove-method #' foo method )))
138138
139139(defun add-methods (list )
140- (loop until *run* do ( sb-thread :thread-yield) )
140+ (sb-thread :wait-on-semaphore *run* )
141141 (dolist (method list )
142142 (add-method #' foo method )))
143143
148148 (make-thread (lambda () (add-methods *to-add-d* )))
149149 (make-thread (lambda () (add-methods *to-add-e* )))
150150 (make-thread (lambda () (add-methods *to-add-f* ))))))
151- (setf *run* t )
151+ (sb-thread :signal-semaphore *run* 6 )
152152 (mapcar #' join-thread threads))
153153
154154#- sb-thread
Original file line number Diff line number Diff line change 6868 (push (find-class ' ,c) *cache-test-classes* )))))))
6969 (def))
7070
71- (defvar *run-cache-test* nil )
71+ (defvar *run-cache-test* ( sb-thread :make-semaphore) )
7272
7373(let* ((instances (map ' vector #' make-instance *cache-test-classes* ))
7474 (limit (length instances)))
9090 (write-line string )))))
9191
9292(defun test-loop ()
93- (loop until *run-cache-test* do ( sb-thread :thread-yield) )
93+ (sb-thread :wait-on-semaphore *run-cache-test* )
9494 (handler-case
9595 (loop repeat 1024 do (test-cache))
9696 (error (e)
103103 #+ sb-thread
104104 (let ((threads (loop repeat 32
105105 collect (sb-thread :make-thread ' test-loop))))
106- (setf *run-cache-test* t )
106+ (sb-thread :signal-semaphore *run-cache-test* 32 )
107107 (mapcar #' sb-thread:join-thread threads))
108108
109109 #- sb-thread
Original file line number Diff line number Diff line change 112112 ` (with-test (:name , name)
113113 (let* ((n 200000 )
114114 (x , init)
115- (run nil )
115+ (run (sb-thread :make-semaphore))
116+ (threadcount 10 )
116117 (threads
117- (loop repeat 10
118+ (loop repeat threadcount
118119 collect (make-thread
119120 (lambda ()
120- (loop until run do ( thread-yield) )
121+ (sb- thread:wait-on-semaphore run )
121122 (loop repeat n do (, incf x)))))))
122- (setf run t )
123+ (sb-thread :signal-semaphore run threadcount )
123124 (map nil #' join-thread threads)
124- (assert (= (, op x) (* 10 n)))))))
125+ (assert (= (, op x) (* threadcount n)))))))
125126
126127 (def (cas car ) (cons 0 nil ) incf-car car )
127128 (def (cas cdr ) (cons nil 0 ) incf-cdr cdr )
You can’t perform that action at this time.
0 commit comments