1 ;;;; miscellaneous tests of thread stuff
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absoluely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
17 (shadowing-import 'assertoid
:assert-error
)
18 (use-package :sb-thread
)
20 (use-package '#:test-util
)
21 (use-package '#:assertoid
)
23 (setf sb-unix
::*on-dangerous-wait
* :error
)
25 (defun wait-for-threads (threads)
26 (mapc (lambda (thread) (join-thread thread
:default nil
)) threads
)
27 (assert (not (some #'thread-alive-p threads
))))
29 (defun process-all-interrupts (&optional
(thread *current-thread
*))
30 (sb-ext:wait-for
(null (sb-thread::thread-interruptions thread
))))
32 (with-test (:name
(:threads
:trivia
))
33 (assert (eql 1 (length (list-all-threads))))
35 (assert (eq *current-thread
*
36 (find (thread-name *current-thread
*) (list-all-threads)
37 :key
#'thread-name
:test
#'equal
)))
39 (assert (thread-alive-p *current-thread
*)))
41 (with-test (:name
(with-mutex :basics
))
42 (let ((mutex (make-mutex)))
46 (sb-alien:define-alien-routine
"check_deferrables_blocked_or_lose"
48 (where sb-alien
:unsigned-long
))
49 (sb-alien:define-alien-routine
"check_deferrables_unblocked_or_lose"
51 (where sb-alien
:unsigned-long
))
53 (with-test (:name
(interrupt-thread :basics
:no-unwinding
))
55 (interrupt-thread *current-thread
* (lambda () (setq a
1)))
56 (process-all-interrupts)
59 (with-test (:name
(interrupt-thread :deferrables-blocked
))
60 (interrupt-thread *current-thread
*
62 ;; Make sure sb-ext:gc doesn't leave the
63 ;; deferrables unblocked
65 (check-deferrables-blocked-or-lose 0)))
66 (process-all-interrupts))
68 (with-test (:name
(interrupt-thread :deferrables-unblocked
))
69 (interrupt-thread *current-thread
*
72 (check-deferrables-unblocked-or-lose 0))))
73 (process-all-interrupts))
75 (with-test (:name
(interrupt-thread :nlx
))
77 (interrupt-thread *current-thread
*
79 (check-deferrables-blocked-or-lose 0)
81 (process-all-interrupts))
82 (check-deferrables-unblocked-or-lose 0))
84 #-sb-thread
(sb-ext:exit
:code
104)
86 ;;;; Now the real tests...
88 (with-test (:name
(with-mutex :timeout
))
89 (let ((m (make-mutex)))
91 (assert (null (join-thread (make-thread
93 (with-mutex (m :timeout
0.1)
95 (assert (join-thread (make-thread
97 (with-mutex (m :timeout
0.1)
102 (defmacro defincf
(name accessor
&rest args
)
104 (let* ((old (,accessor x
,@args
))
106 (loop until
(eq old
(sb-ext:compare-and-swap
(,accessor x
,@args
) old new
))
107 do
(setf old
(,accessor x
,@args
)
111 (defstruct cas-struct
(slot 0))
113 (defincf incf-car car
)
114 (defincf incf-cdr cdr
)
115 (defincf incf-slot cas-struct-slot
)
116 (defincf incf-symbol-value symbol-value
)
117 (defincf incf-svref
/1 svref
1)
118 (defincf incf-svref
/0 svref
0)
121 ((def (name init incf op
)
122 `(with-test (:name
,name
)
130 (loop until run do
(thread-yield))
131 (loop repeat n do
(,incf x
)))))))
133 (map nil
#'join-thread threads
)
134 (assert (= (,op x
) (* 10 n
)))))))
136 (def (cas car
) (cons 0 nil
) incf-car car
)
137 (def (cas cdr
) (cons nil
0) incf-cdr cdr
)
138 (def (cas :slot
) (make-cas-struct) incf-slot cas-struct-slot
)
145 (def (cas :svref
/0) (vector 0 nil
) incf-svref
/0 (lambda (x) (svref x
0)))
146 (def (cas :svref
/1) (vector nil
0) incf-svref
/1 (lambda (x) (svref x
1))))
148 (with-test (:name
(:threads
:more-trivia
))
149 (let ((old-threads (list-all-threads))
150 (thread (make-thread (lambda ()
151 (assert (find *current-thread
*
152 sb-thread
::*all-threads
*))
154 (new-threads (list-all-threads)))
155 (assert (thread-alive-p thread
))
156 (assert (eq thread
(first new-threads
)))
157 (assert (= (1+ (length old-threads
)) (length new-threads
)))
159 (assert (not (thread-alive-p thread
)))))
161 (with-test (:name
(join-thread :abort
:default
))
162 (let* ((sym (gensym))
163 (thread (make-thread (lambda () (abort-thread)))))
164 (assert (equal (multiple-value-list
165 (join-thread thread
:default sym
))
166 (list sym
:abort
)))))
168 (with-test (:name
(join-thread :abort
:error
))
169 (assert-error (join-thread (make-thread (lambda () (abort-thread))))
172 (with-test (:name
(join-thread :timeout
:default
))
173 (let* ((sym (gensym))
174 (sem (make-semaphore))
175 (thread (make-thread (lambda () (wait-on-semaphore sem
)))))
176 (assert (equal (multiple-value-list
177 (join-thread thread
:timeout
.001 :default sym
))
178 (list sym
:timeout
)))
179 (signal-semaphore sem
)
180 (assert (join-thread thread
))))
182 (with-test (:name
(join-thread :timeout
:error
))
183 (let* ((sem (make-semaphore))
184 (thread (make-thread (lambda () (wait-on-semaphore sem
)))))
185 (assert-error (join-thread thread
:timeout
.001) join-thread-error
)
186 (signal-semaphore sem
)
187 (assert (join-thread thread
))))
189 (with-test (:name
(join-thread :multiple-values
))
190 (assert (equal '(1 2 3)
192 (join-thread (make-thread (lambda () (values 1 2 3))))))))
194 ;; Used to signal a SIMPLE-ERROR about a recursive lock attempt.
195 (with-test (:name
(join-thread :self-join
))
196 (assert-error (join-thread *current-thread
*) join-thread-error
))
198 ;;; We had appalling scaling properties for a while. Make sure they
200 (defun scaling-test (function &optional
(nthreads 5))
201 "Execute FUNCTION with NTHREADS lurking to slow it down."
202 (let ((queue (make-waitqueue))
203 (mutex (make-mutex)))
204 ;; Start NTHREADS idle threads.
205 (dotimes (i nthreads
)
206 (make-join-thread (lambda ()
208 (condition-wait queue mutex
))
210 (prog1 (runtime (funcall function
))
211 (condition-broadcast queue
))))
214 "A function that does work with the CPU."
215 (if (zerop n
) 1 (* n
(fact (1- n
)))))
217 (with-test (:name
:lurking-threads
)
218 (let ((work (lambda () (fact 15000))))
219 (let ((zero (scaling-test work
0))
220 (four (scaling-test work
4)))
221 ;; a slightly weak assertion, but good enough for starters.
222 (assert (< four
(* 2 zero
))))))
224 ;;; For one of the interupt-thread tests, we want a foreign function
225 ;;; that does not make syscalls
229 (with-open-file (o "threads-foreign.c" :direction
:output
:if-exists
:supersede
)
230 (format o
"void loop_forever() { while(1) ; }~%"))
231 (sb-ext:run-program
"/bin/sh"
232 '("run-compiler.sh" "-sbcl-pic" "-sbcl-shared"
233 "-o" "threads-foreign.so" "threads-foreign.c"))
234 (sb-alien:load-shared-object
(truename "threads-foreign.so"))
235 (sb-alien:define-alien-routine loop-forever sb-alien
:void
)
236 (delete-file "threads-foreign.c"))
238 ;;; elementary "can we get a lock and release it again"
239 (with-test (:name
(:mutex
:basics
))
240 (let ((l (make-mutex :name
"foo"))
241 (p *current-thread
*))
242 (assert (eql (mutex-value l
) nil
) nil
"1")
244 (assert (eql (mutex-value l
) p
) nil
"3")
246 (assert (eql (mutex-value l
) nil
) nil
"5")))
248 (with-test (:name
(with-recursive-lock :basics
))
249 (labels ((ours-p (value)
250 (eq *current-thread
* value
)))
251 (let ((l (make-mutex :name
"rec")))
252 (assert (eql (mutex-value l
) nil
) nil
"1")
253 (with-recursive-lock (l)
254 (assert (ours-p (mutex-value l
)) nil
"3")
255 (with-recursive-lock (l)
256 (assert (ours-p (mutex-value l
)) nil
"4"))
257 (assert (ours-p (mutex-value l
)) nil
"5"))
258 (assert (eql (mutex-value l
) nil
) nil
"6"))))
260 (with-test (:name
(with-recursive-lock :wait-p
))
261 (let ((m (make-mutex)))
263 (assert (null (join-thread (make-thread
265 (with-recursive-lock (m :wait-p nil
)
267 (assert (join-thread (make-thread
269 (with-recursive-lock (m :wait-p nil
)
272 (with-test (:name
(with-recursive-lock :wait-p
:recursive
))
273 (let ((m (make-mutex)))
274 (assert (join-thread (make-thread
276 (with-recursive-lock (m :wait-p nil
)
277 (with-recursive-lock (m :wait-p nil
)
280 (with-test (:name
(with-recursive-lock :timeout
))
281 (let ((m (make-mutex)))
283 (assert (null (join-thread (make-thread
285 (with-recursive-lock (m :timeout
0.1)
287 (assert (join-thread (make-thread
289 (with-recursive-lock (m :timeout
0.1)
292 (with-test (:name
(with-recursive-lock :timeout
:recursive
))
293 (let ((m (make-mutex)))
294 (assert (join-thread (make-thread
296 (with-recursive-lock (m :timeout
0.1)
297 (with-recursive-lock (m :timeout
0.1)
300 (with-test (:name
(:mutex
:nesting-mutex-and-recursive-lock
))
301 (let ((l (make-mutex :name
"a mutex")))
303 (with-recursive-lock (l)))))
305 ;; test that SLEEP actually sleeps for at least the given time, even
306 ;; if interrupted by another thread exiting/a gc/anything
307 (with-test (:name
(sleep :continue-sleeping-after-interrupt
))
308 (let ((start-time (get-universal-time)))
309 (make-join-thread (lambda () (sleep 1) (sb-ext:gc
:full t
)))
311 (assert (>= (get-universal-time) (+ 5 start-time
)))))
314 (with-test (:name
(condition-wait :basics-1
))
315 (let ((queue (make-waitqueue :name
"queue"))
316 (lock (make-mutex :name
"lock"))
318 (labels ((in-new-thread ()
320 (assert (eql (mutex-value lock
) *current-thread
*))
321 (format t
"~A got mutex~%" *current-thread
*)
322 ;; now drop it and sleep
323 (condition-wait queue lock
)
324 ;; after waking we should have the lock again
325 (assert (eql (mutex-value lock
) *current-thread
*))
328 (make-join-thread #'in-new-thread
)
329 (sleep 2) ; give it a chance to start
330 ;; check the lock is free while it's asleep
331 (format t
"parent thread ~A~%" *current-thread
*)
332 (assert (eql (mutex-value lock
) nil
))
335 (condition-notify queue
))
338 (with-test (:name
(condition-wait :basics-2
))
339 (let ((queue (make-waitqueue :name
"queue"))
340 (lock (make-mutex :name
"lock")))
341 (labels ((ours-p (value)
342 (eq *current-thread
* value
))
344 (with-recursive-lock (lock)
345 (assert (ours-p (mutex-value lock
)))
346 (format t
"~A got mutex~%" (mutex-value lock
))
347 ;; now drop it and sleep
348 (condition-wait queue lock
)
349 ;; after waking we should have the lock again
350 (format t
"woken, ~A got mutex~%" (mutex-value lock
))
351 (assert (ours-p (mutex-value lock
))))))
352 (make-join-thread #'in-new-thread
)
353 (sleep 2) ; give it a chance to start
354 ;; check the lock is free while it's asleep
355 (format t
"parent thread ~A~%" *current-thread
*)
356 (assert (eql (mutex-value lock
) nil
))
357 (with-recursive-lock (lock)
358 (condition-notify queue
))
361 (with-test (:name
(:mutex
:contention
))
362 (let ((mutex (make-mutex :name
"contended")))
364 (let ((me *current-thread
*))
368 (assert (eql (mutex-value mutex
) me
)))
369 (assert (not (eql (mutex-value mutex
) me
))))
370 (format t
"done ~A~%" *current-thread
*))))
371 (let ((kid1 (make-thread #'run
))
372 (kid2 (make-thread #'run
)))
373 (format t
"contention ~A ~A~%" kid1 kid2
)
374 (wait-for-threads (list kid1 kid2
))))))
378 (with-test (:name
(grab-mutex :waitp nil
))
379 (let ((m (make-mutex)))
381 (assert (null (join-thread (make-thread
383 (grab-mutex m
:waitp nil
)))))))))
385 (with-test (:name
(grab-mutex :timeout
:acquisition-fail
))
386 (let ((m (make-mutex))
387 (w (make-semaphore)))
389 (let ((th (make-thread
392 (grab-mutex m
:timeout
0.1)
393 (signal-semaphore w
))))))
394 ;; Wait for it to -- otherwise the detect the deadlock chain
396 (wait-on-semaphore w
)
397 (assert (null (join-thread th
)))))))
399 (with-test (:name
(grab-mutex :timeout
:acquisition-success
))
400 (let ((m (make-mutex))
403 (setq child
(make-thread #'(lambda () (grab-mutex m
:timeout
1.0))))
405 (assert (eq (join-thread child
) 't
))))
407 (with-test (:name
(grab-mutex :timeout
+deadline
:lp-1727789
))
408 (flet ((test (deadline)
409 (let ((m (make-mutex))
410 (w (make-semaphore)))
412 (let ((th (make-thread #'(lambda ()
413 (sb-sys:with-deadline
(:seconds
0.0)
415 (grab-mutex m
:timeout deadline
)
416 (sb-sys:deadline-timeout
()
419 (wait-on-semaphore w
)
420 (assert (eq (join-thread th
) :deadline
)))))))
422 (test 10000000000000000000000)))
424 (with-test (:name
(grab-mutex :waitp
+deadline
))
425 (let ((m (make-mutex)))
427 (assert (eq (join-thread
428 (make-thread #'(lambda ()
429 (sb-sys:with-deadline
(:seconds
0.0)
431 (grab-mutex m
:waitp nil
)
432 (sb-sys:deadline-timeout
()
438 (defmacro raises-timeout-p
(&body body
)
439 `(handler-case (progn (progn ,@body
) nil
)
440 (sb-ext:timeout
() t
)))
442 (with-test (:name
(semaphore :wait-forever
))
443 (let ((sem (make-semaphore :count
0)))
444 (assert (raises-timeout-p
445 (sb-ext:with-timeout
0.1
446 (wait-on-semaphore sem
))))))
448 (with-test (:name
(semaphore :initial-count
))
449 (let ((sem (make-semaphore :count
1)))
450 (sb-ext:with-timeout
0.1
451 (assert (= 0 (wait-on-semaphore sem
))))))
453 (with-test (:name
(semaphore :wait-then-signal
))
454 (let ((sem (make-semaphore))
456 (make-join-thread (lambda ()
459 (signal-semaphore sem
)))
460 (assert (= 0 (wait-on-semaphore sem
)))
461 (assert signalled-p
)))
463 (with-test (:name
(semaphore :signal-then-wait
))
464 (let ((sem (make-semaphore))
466 (make-join-thread (lambda ()
467 (signal-semaphore sem
)
468 (setq signalled-p t
)))
469 (loop until signalled-p
)
470 (assert (= 0 (wait-on-semaphore sem
)))
471 (assert signalled-p
)))
473 (defun test-semaphore-multiple-signals (wait-on-semaphore)
474 (let* ((sem (make-semaphore :count
5))
475 (threads (loop repeat
20 collecting
476 (make-join-thread (lambda ()
477 (funcall wait-on-semaphore sem
))))))
478 (flet ((count-live-threads ()
479 (count-if #'thread-alive-p threads
)))
481 (assert (= 15 (count-live-threads)))
482 (signal-semaphore sem
10)
484 (assert (= 5 (count-live-threads)))
485 (signal-semaphore sem
3)
487 (assert (= 2 (count-live-threads)))
488 (signal-semaphore sem
4)
490 (assert (= 0 (count-live-threads))))))
492 (with-test (:name
(semaphore :multiple-signals
))
493 (test-semaphore-multiple-signals #'wait-on-semaphore
))
495 (with-test (:name
(try-semaphore :trivial-fail
))
496 (assert (eq (try-semaphore (make-semaphore :count
0)) 'nil
)))
498 (with-test (:name
(try-semaphore :trivial-success
))
499 (let ((sem (make-semaphore :count
1)))
500 (assert (= 0 (try-semaphore sem
)))
501 (assert (zerop (semaphore-count sem
)))))
503 (with-test (:name
(try-semaphore :trivial-fail
:n
>1))
504 (assert (eq (try-semaphore (make-semaphore :count
1) 2) 'nil
)))
506 (with-test (:name
(try-semaphore :trivial-success
:n
>1))
507 (let ((sem (make-semaphore :count
10)))
508 (assert (= 5 (try-semaphore sem
5)))
509 (assert (= 0 (try-semaphore sem
5)))
510 (assert (zerop (semaphore-count sem
)))))
512 (with-test (:name
(try-semaphore :emulate-wait-on-semaphore
))
513 (flet ((busy-wait-on-semaphore (sem)
514 (loop until
(try-semaphore sem
) do
(sleep 0.001))))
515 (test-semaphore-multiple-signals #'busy-wait-on-semaphore
)))
517 ;;; Here we test that interrupting TRY-SEMAPHORE does not leave a
518 ;;; semaphore in a bad state.
519 (with-test (:name
(try-semaphore :interrupt-safe
)
521 (flet ((make-threads (count fn
)
522 (loop repeat count collect
(make-thread fn
)))
523 (kill-thread (thread)
524 (when (thread-alive-p thread
)
525 (ignore-errors (terminate-thread thread
))))
526 (count-live-threads (threads)
527 (count-if #'thread-alive-p threads
)))
528 ;; WAITERS will already be waiting on the semaphore while
529 ;; threads-being-interrupted will perform TRY-SEMAPHORE on that
530 ;; semaphore, and MORE-WAITERS are new threads trying to wait on
531 ;; the semaphore during the interruption-fire.
532 (let* ((sem (make-semaphore :count
100))
533 (waiters (make-threads 20 #'(lambda ()
534 (wait-on-semaphore sem
))))
535 (triers (make-threads 40 #'(lambda ()
536 (sleep (random 0.01))
537 (try-semaphore sem
(1+ (random 5))))))
540 do
(kill-thread (nth (random 40) triers
))
541 collect
(make-thread #'(lambda () (wait-on-semaphore sem
)))
542 do
(kill-thread (nth (random 40) triers
)))))
544 ;; Now ensure that the waiting threads will all be waked up,
545 ;; i.e. that the semaphore is still working.
546 (loop repeat
(+ (count-live-threads waiters
)
547 (count-live-threads more-waiters
))
548 do
(signal-semaphore sem
))
550 (assert (zerop (count-live-threads triers
)))
551 (assert (zerop (count-live-threads waiters
)))
552 (assert (zerop (count-live-threads more-waiters
))))))
554 ;; At some point %DECREMENT-SEMAPHORE did not adjust the remaining
555 ;; timeout after spurious wakeups, potentially leading to
556 ;; longer/infinite waiting despite the specified timeout.
557 (with-test (:name
(semaphore :timeout
:spurious-wakeup
))
558 (let* ((semaphore (make-semaphore))
560 (thread (make-thread (lambda ()
561 (let ((mutex (sb-thread::semaphore-mutex semaphore
))
562 (queue (sb-thread::semaphore-queue semaphore
)))
563 (loop :until done
:do
565 (condition-notify queue
))))))))
566 (assert (eq nil
(wait-on-semaphore semaphore
:timeout
.5)))
568 (join-thread thread
)))
570 (defun test-interrupt (function-to-interrupt &optional quit-p
)
571 (let ((child (make-kill-thread function-to-interrupt
)))
572 (format t
"interrupting child ~A~%" child
)
573 (interrupt-thread child
575 (format t
"child pid ~A~%" *current-thread
*)
576 (when quit-p
(abort-thread))))
577 (process-all-interrupts child
)
580 ;; separate tests for (a) interrupting Lisp code, (b) C code, (c) a syscall,
581 ;; (d) waiting on a lock, (e) some code which we hope is likely to be
584 (with-test (:name
(interrupt-thread :more-basics
)
586 (let ((child (test-interrupt (lambda () (loop)))))
587 (terminate-thread child
)))
589 (with-test (:name
(interrupt-thread :interrupt-foreign-loop
)
590 ;; This feature is explicitly unsupported on Win32.
592 (test-interrupt #'loop-forever
:quit
))
594 (with-test (:name
(interrupt-thread :interrupt-sleep
)
596 (let ((child (test-interrupt (lambda () (loop (sleep 2000))))))
597 (terminate-thread child
)
598 (wait-for-threads (list child
))))
600 (with-test (:name
(interrupt-thread :interrupt-mutex-acquisition
)
602 (let ((lock (make-mutex :name
"loctite"))
605 (setf child
(test-interrupt
608 (assert (eql (mutex-value lock
) *current-thread
*)))
609 (assert (not (eql (mutex-value lock
) *current-thread
*)))
611 ;;hold onto lock for long enough that child can't get it immediately
613 (interrupt-thread child
(lambda () (format t
"l ~A~%" (mutex-value lock
))))
614 (format t
"parent releasing lock~%"))
615 (process-all-interrupts child
)
616 (terminate-thread child
)
617 (wait-for-threads (list child
))))
619 (defun alloc-stuff () (copy-list '(1 2 3 4 5)))
621 (with-test (:name
(interrupt-thread :interrupt-consing-child
)
623 (let ((thread (make-thread (lambda () (loop (alloc-stuff))))))
625 (loop repeat
4 collect
629 (sleep (random 0.1d0
))
632 (interrupt-thread thread
(lambda ()))))))))
633 (wait-for-threads killers
)
634 (process-all-interrupts thread
)
635 (terminate-thread thread
)
636 (wait-for-threads (list thread
))))
639 #+(or x86 x86-64
) ;; x86oid-only, see internal commentary.
640 (with-test (:name
(interrupt-thread :interrupt-consing-child
:again
)
642 (let ((c (make-thread (lambda () (loop (alloc-stuff))))))
643 ;; NB this only works on x86: other ports don't have a symbol for
644 ;; pseudo-atomic atomicity
646 (sleep (random 0.1d0
))
649 (princ ".") (force-output)
650 (assert (thread-alive-p *current-thread
*))
652 (not (logbitp 0 SB-KERNEL
:*PSEUDO-ATOMIC-BITS
*))))))
653 (process-all-interrupts c
)
655 (wait-for-threads (list c
))))
657 (defstruct counter
(n 0 :type sb-vm
:word
))
658 (defvar *interrupt-counter
* (make-counter))
660 (declaim (notinline check-interrupt-count
))
661 (defun check-interrupt-count (i)
662 (declare (optimize (debug 1) (speed 1)))
663 ;; This used to lose if eflags were not restored after an interrupt.
664 (unless (typep i
'fixnum
)
665 (error "!!!!!!!!!!!")))
667 (with-test (:name
(interrupt-thread :interrupt-ATOMIC-INCF
)
669 (let ((c (make-thread
671 (handler-bind ((error #'(lambda (cond)
673 (sb-debug:print-backtrace
674 :count most-positive-fixnum
))))
675 (loop (check-interrupt-count
676 (counter-n *interrupt-counter
*))))))))
677 (let ((func (lambda ()
680 (sb-ext:atomic-incf
(counter-n *interrupt-counter
*)))))
681 (setf (counter-n *interrupt-counter
*) 0)
683 (sleep (random 0.1d0
))
684 (interrupt-thread c func
))
685 (loop until
(= (counter-n *interrupt-counter
*) 100) do
(sleep 0.1))
687 (wait-for-threads (list c
)))))
689 (defvar *runningp
* nil
)
691 (with-test (:name
(interrupt-thread :no-nesting
) :broken-on
:win32
)
692 (let ((thread (make-thread (lambda ()
695 (declare (special runningp
))
697 (interrupt-thread thread
(lambda ()
698 (let ((*runningp
* t
))
701 (interrupt-thread thread
(lambda ()
702 (throw 'xxx
*runningp
*)))
703 (assert (not (join-thread thread
)))))
705 (with-test (:name
(interrupt-thread :nesting
) :broken-on
:win32
)
706 (let ((thread (make-thread (lambda ()
709 (declare (special runningp
))
711 (interrupt-thread thread
(lambda ()
712 (let ((*runningp
* t
))
713 (sb-sys:with-interrupts
716 (interrupt-thread thread
(lambda ()
717 (throw 'xxx
*runningp
*)))
718 (assert (join-thread thread
))))
720 (with-test (:name
(:two-threads-running-gc
)
721 :broken-on
:sb-safepoint
)
723 (make-join-thread (lambda ()
725 (sb-ext:gc
) (princ "\\") (force-output))
727 (make-join-thread (lambda ()
730 (princ "/") (force-output))
733 (when (and a-done b-done
) (return))
736 (defun waste (&optional
(n 100000))
737 (loop repeat n do
(make-string 16384)))
741 (with-test (:name
(:one-thread-runs-gc-while-other-conses
)
743 (loop for i below
100 do
752 (defparameter *aaa
* nil
)
753 (with-test (:name
(:one-thread-runs-gc-while-other-conses
:again
))
754 (loop for i below
100 do
759 (let ((*aaa
* (waste)))
761 (let ((*aaa
* (waste)))
765 (defun exercise-syscall (fn reference-errno
)
770 (let ((errno (sb-unix::get-errno
)))
771 (sleep (random 0.1d0
))
772 (unless (eql errno reference-errno
)
773 (format t
"Got errno: ~A (~A) instead of ~A~%"
780 ;; (nanosleep -1 0) does not fail on FreeBSD
781 (with-test (:name
(:exercising-concurrent-syscalls
)
784 (nanosleep-errno (progn
785 (sb-unix:nanosleep -
1 0)
786 (sb-unix::get-errno
)))
789 :if-does-not-exist nil
)
790 (sb-unix::get-errno
)))
794 (exercise-syscall (lambda () (sb-unix:nanosleep -
1 0)) nanosleep-errno
)
795 (exercise-syscall (lambda () (open "no-such-file"
796 :if-does-not-exist nil
))
798 (make-join-thread (lambda () (loop (sb-ext:gc
) (sleep 1)))))))
800 (princ "terminating threads")
801 (dolist (thread threads
)
802 (terminate-thread thread
))))
804 (with-test (:name
:all-threads-have-abort-restart
807 (let ((thread (make-kill-thread (lambda () (sleep 0.1)))))
808 (interrupt-thread thread
(lambda ()
809 (assert (find-restart 'abort
))))
810 (process-all-interrupts thread
))))
814 ;; expose thread creation races by exiting quickly
815 (with-test (:name
(:no-thread-creation-race
:light
))
816 (make-join-thread (lambda ())))
818 (with-test (:name
(:no-thread-creation-race
:heavy
))
821 (loop for i below
100 collect
822 (make-thread (lambda ()))))))
824 ;; interrupt handlers are per-thread with pthreads, make sure the
825 ;; handler installed in one thread is global
826 (with-test (:name
(:global-interrupt-handler
))
829 (sb-ext:run-program
"sleep" '("1") :search t
:wait nil
))))
831 ;;;; Binding stack safety
833 (defparameter *x
* nil
)
834 (defparameter *n-gcs-requested
* 0)
835 (defparameter *n-gcs-done
* 0)
838 (defun make-something-big ()
839 (let ((x (make-string 32000)))
841 (let ((counter counter
))
842 (sb-ext:finalize x
(lambda () (format t
" ~S" counter
)
845 (defmacro wait-for-gc
()
847 (incf *n-gcs-requested
*)
848 (loop while
(< *n-gcs-done
* *n-gcs-requested
*))))
851 (loop until
(< *n-gcs-done
* *n-gcs-requested
*))
857 #+(or x86 x86-64
) ;the only platforms with a *binding-stack-pointer* variable
858 (defun exercise-binding ()
860 (let ((*x
* (make-something-big)))
862 ;; at this point the binding stack looks like this:
863 ;; NO-TLS-VALUE-MARKER, *x*, SOMETHING, *x*
866 ;; sig_stop_for_gc_handler binds FREE_INTERRUPT_CONTEXT_INDEX. By
867 ;; now SOMETHING is gc'ed and the binding stack looks like this: 0,
868 ;; 0, SOMETHING, 0 (because the symbol slots are zeroed on
869 ;; unbinding but values are not).
871 (binding-pointer-delta (ash 2 (- sb-vm
:word-shift sb-vm
:n-fixnum-tag-bits
))))
872 ;; bump bsp as if a BIND had just started
873 (incf sb-vm
::*binding-stack-pointer
* binding-pointer-delta
)
875 (decf sb-vm
::*binding-stack-pointer
* binding-pointer-delta
))))
877 #+(or x86 x86-64
) ;the only platforms with a *binding-stack-pointer* variable
878 (with-test (:name
(:binding-stack-gc-safety
)
883 (push (make-kill-thread #'exercise-binding
) threads
)
884 (push (make-kill-thread (lambda ()
890 (mapc #'terminate-thread threads
))))
892 ;; No interpreter stub
893 (defun symbol-tls-index (symbol)
894 (sb-kernel:symbol-tls-index symbol
))
895 (compile 'symbol-tls-index
)
897 (with-test (:name
:test-%thread-local-references
)
899 (let ((mysym (gensym))
902 (progv (list mysym
) '(nil)
903 (let* ((i (sb-kernel:get-lisp-obj-address
(symbol-tls-index mysym
)))
904 (j (+ i sb-vm
:n-word-bytes
)))
905 (assert (eql (sap-ref-word (sb-thread::current-thread-sap
) j
)
906 sb-vm
:no-tls-value-marker-widetag
))
907 (setf (sap-ref-lispobj (sb-thread::current-thread-sap
) i
) fool1
908 (sap-ref-lispobj (sb-thread::current-thread-sap
) j
) fool2
)
909 ;; assert that my pointer arithmetic worked as expected
910 (assert (eq (symbol-value mysym
) fool1
))
911 ;; assert that FOOL1 is found by the TLS scan and that FOOL2 is not.
912 (let ((list (sb-thread::%thread-local-references
)))
913 (assert (member fool1 list
))
914 (assert (not (member fool2 list
))))
915 ;; repair the TLS entry that was corrupted by the test
916 (setf (sap-ref-word (sb-thread::current-thread-sap
) j
)
917 sb-vm
:no-tls-value-marker-widetag
)))))
921 (defvar *errors
* nil
)
925 (format t
"~&oops: ~A in ~S~%" e
*current-thread
*)
926 (sb-debug:print-backtrace
)
929 (with-test (:name
(hash-table :unsynchronized
)
930 ;; FIXME: This test occasionally eats out craploads
931 ;; of heap instead of expected error early. Not 100%
932 ;; sure if it would finish as expected, but since it
933 ;; hits swap on my system I'm not likely to find out
934 ;; soon. Disabling for now. -- nikodemus
936 ;; We expect a (probable) error here: parellel readers and writers
937 ;; on a hash-table are not expected to work -- but we also don't
938 ;; expect this to corrupt the image.
939 (let* ((hash (make-hash-table))
941 (threads (list (make-kill-thread
944 (handler-bind ((serious-condition 'oops
))
946 ;;(princ "1") (force-output)
947 (setf (gethash (random 100) hash
) 'h
)))))
952 (handler-bind ((serious-condition 'oops
))
954 ;;(princ "2") (force-output)
955 (remhash (random 100) hash
)))))
960 (handler-bind ((serious-condition 'oops
))
963 (sb-ext:gc
:full t
)))))
964 :name
"collector"))))
967 (mapc #'terminate-thread threads
))))
969 (with-test (:name
(hash-table :synchronized
)
971 (let* ((hash (make-hash-table :synchronized t
))
973 (threads (list (make-join-thread
976 (handler-bind ((serious-condition 'oops
))
978 ;;(princ "1") (force-output)
979 (setf (gethash (random 100) hash
) 'h
)))))
984 (handler-bind ((serious-condition 'oops
))
986 ;;(princ "2") (force-output)
987 (remhash (random 100) hash
)))))
992 (handler-bind ((serious-condition 'oops
))
995 (sb-ext:gc
:full t
)))))
996 :name
"collector"))))
999 (mapc #'terminate-thread threads
))
1000 (assert (not *errors
*))))
1002 (with-test (:name
(hash-table :parallel-readers
)
1004 (let ((hash (make-hash-table))
1007 do
(setf (gethash (random 100) hash
) 'xxx
))
1008 (let ((threads (list (make-kill-thread
1011 (handler-bind ((serious-condition 'oops
))
1013 until
(eq t
(gethash (random 100) hash
))))))
1018 (handler-bind ((serious-condition 'oops
))
1020 until
(eq t
(gethash (random 100) hash
))))))
1025 (handler-bind ((serious-condition 'oops
))
1027 until
(eq t
(gethash (random 100) hash
))))))
1032 (handler-bind ((serious-condition 'oops
))
1034 (sleep (random 1.0))
1035 (sb-ext:gc
:full t
)))))
1036 :name
"collector"))))
1039 (mapc #'terminate-thread threads
))
1040 (assert (not *errors
*)))))
1042 (with-test (:name
(hash-table :single-accessor
:parallel-gc
)
1044 (let ((hash (make-hash-table))
1046 (let ((threads (list (make-kill-thread
1048 (handler-bind ((serious-condition 'oops
))
1050 (let ((n (random 100)))
1051 (if (gethash n hash
)
1053 (setf (gethash n hash
) 'h
))))))
1057 (handler-bind ((serious-condition 'oops
))
1059 (sleep (random 1.0))
1060 (sb-ext:gc
:full t
))))
1061 :name
"collector"))))
1064 (mapc #'terminate-thread threads
))
1065 (assert (not *errors
*)))))
1067 #|
;; a cll post from eric marsden
1069 |
(setq *debugger-hook
*
1070 |
(lambda (condition old-debugger-hook
)
1071 |
(debug:backtrace
10)
1072 |
(unix:unix-exit
2)))
1073 |
#+live-dangerously
1074 |
(mp::start-sigalrm-yield
)
1075 |
(flet ((roomy () (loop (with-output-to-string (*standard-output
*) (room)))))
1076 |
(mp:make-process
#'roomy
)
1077 |
(mp:make-process
#'roomy
)))
1080 (with-test (:name
(:condition-variable
:notify-multiple
)
1082 (flet ((tester (notify-fun)
1083 (let ((queue (make-waitqueue :name
"queue"))
1084 (lock (make-mutex :name
"lock"))
1089 (format t
"condition-wait ~a~%" x
)
1091 (condition-wait queue lock
)
1092 (format t
"woke up ~a~%" x
)
1095 (let ((threads (loop for x from
1 to
10
1098 (make-kill-thread (lambda ()
1102 (funcall notify-fun queue
))
1104 (mapcar #'terminate-thread threads
)
1105 ;; Check that all threads woke up at least once
1106 (assert (= (length (remove-duplicates data
)) 10)))))))
1107 (tester (lambda (queue)
1108 (format t
"~&(condition-notify queue 10)~%")
1110 (condition-notify queue
10)))
1111 (tester (lambda (queue)
1112 (format t
"~&(condition-broadcast queue)~%")
1114 (condition-broadcast queue
)))))
1116 ;;; Make sure that a deadline handler is not invoked twice in a row in
1117 ;;; CONDITION-WAIT. See LP #512914 for a detailed explanation.
1119 (with-test (:name
(condition-wait :deadlines
:LP-512914
))
1120 (let ((n 2) ; was empirically enough to trigger the bug
1121 (mutex (make-mutex))
1122 (waitq (make-waitqueue))
1124 (deadline-handler-run-twice? nil
))
1130 ((sb-sys:deadline-timeout
1131 (let ((already? nil
))
1134 (setq deadline-handler-run-twice? t
))
1137 (sb-thread:condition-broadcast waitq
)
1138 (sb-sys:defer-deadline
10.0 c
)))))
1139 (sb-sys:with-deadline
(:seconds
0.1)
1141 (condition-wait waitq mutex
))))))))
1142 (push child threads
)))
1143 (mapc #'join-thread threads
)
1144 (assert (not deadline-handler-run-twice?
))))
1146 (with-test (:name
(condition-wait :signal-deadline-with-interrupts-enabled
))
1147 (let ((mutex (make-mutex))
1148 (waitq (make-waitqueue))
1151 (A-interrupts-enabled?
:unknown
)
1152 (B-interrupts-enabled?
:unknown
)
1155 ;; W.L.O.G., we assume that A is executed first...
1156 (setq A
(make-thread
1159 ((sb-sys:deadline-timeout
1161 ;; We came here through the call to DECODE-TIMEOUT
1162 ;; in CONDITION-WAIT; hence both here are supposed
1163 ;; to evaluate to T.
1164 (setq A-holds?
(holding-mutex-p mutex
))
1165 (setq A-interrupts-enabled?
1166 sb-sys
:*interrupts-enabled
*)
1168 (condition-broadcast waitq
)
1169 (sb-sys:defer-deadline
10.0 c
))))
1170 (sb-sys:with-deadline
(:seconds
0.1)
1172 (condition-wait waitq mutex
)))))
1174 (setq B
(make-thread
1178 ((sb-sys:deadline-timeout
1180 ;; We came here through the call to DECODE-TIMEOUT
1181 ;; in CONDITION-WAIT (contended case of
1182 ;; reaquiring the mutex) - so the former will
1183 ;; be NIL, but interrupts should still be enabled.
1184 (setq B-holds?
(holding-mutex-p mutex
))
1185 (setq B-interrupts-enabled?
1186 sb-sys
:*interrupts-enabled
*)
1188 (condition-broadcast waitq
)
1189 (sb-sys:defer-deadline
10.0 c
))))
1190 (sb-sys:with-deadline
(:seconds
0.1)
1192 (condition-wait waitq mutex
)))))
1196 (let ((A-result (list A-holds? A-interrupts-enabled?
))
1197 (B-result (list B-holds? B-interrupts-enabled?
)))
1198 ;; We also check some subtle behaviour w.r.t. whether a deadline
1199 ;; handler in CONDITION-WAIT got the mutex, or not. This is most
1200 ;; probably very internal behaviour (so user should not depend
1201 ;; on it) -- I added the testing here just to manifest current
1203 (cond ((equal A-result
'(t t
)) (assert (equal B-result
'(nil t
))))
1204 ((equal B-result
'(t t
)) (assert (equal A-result
'(nil t
))))
1206 (error "Failure: fell through wit A: ~S, B: ~S"
1210 (with-test (:name
(:mutex
:finalization
))
1213 (setf a
(make-mutex)))))
1215 ;; You have to shoehorn this arbitrary sexpr into a feature expression
1216 ;; to have the test summary show that a test was disabled.
1218 (unless (eql (extern-alien "verify_gens" int
)
1219 (1+ sb-vm
:+highest-normal-generation
+))
1220 (pushnew :verify-gens
*features
*))
1222 (with-test (:name
:backtrace
:broken-on
:verify-gens
)
1223 ;; Printing backtraces from several threads at once used to hang the
1224 ;; whole SBCL process (discovered by accident due to a timer.impure
1225 ;; test misbehaving). The cause was that packages weren't even
1226 ;; thread-safe for only doing FIND-SYMBOL, and while printing
1227 ;; backtraces a loot of symbol lookups need to be done due to
1229 (let* ((threads (loop repeat
10
1230 collect
(make-thread
1233 (with-output-to-string (*debug-io
*)
1234 (sb-debug:print-backtrace
:count
10))))))))
1235 (wait-for-threads threads
)))
1237 (with-test (:name
:gc-deadlock
1239 (write-line "WARNING: THIS TEST WILL HANG ON FAILURE!")
1240 ;; Prior to 0.9.16.46 thread exit potentially deadlocked the
1241 ;; GC due to *all-threads-lock* and session lock. On earlier
1242 ;; versions and at least on one specific box this test is good enough
1243 ;; to catch that typically well before the 1500th iteration.
1250 (when (zerop (mod i
100))
1257 (sleep (random 0.001)))
1258 :name
(format nil
"SLEEP-~D" i
))
1261 ;; KLUDGE: what we are doing here is explicit,
1262 ;; but the same can happen because of a regular
1263 ;; MAKE-THREAD or LIST-ALL-THREADS, and various
1264 ;; session functions.
1265 (sb-thread::with-all-threads-lock
1266 (sb-thread::with-session-lock
(sb-thread::*session
*)
1268 :name
(format nil
"GC-~D" i
)))
1270 (format t
"~%error creating thread ~D: ~A -- backing off for retry~%" i e
)
1275 (let ((count (make-array 8 :initial-element
0)))
1276 (defun closure-one ()
1277 (declare (optimize safety
))
1278 (values (incf (aref count
0)) (incf (aref count
1))
1279 (incf (aref count
2)) (incf (aref count
3))
1280 (incf (aref count
4)) (incf (aref count
5))
1281 (incf (aref count
6)) (incf (aref count
7))))
1282 (defun no-optimizing-away-closure-one ()
1283 (setf count
(make-array 8 :initial-element
0))))
1288 (let ((one (make-box))
1291 (defun closure-two ()
1292 (declare (optimize safety
))
1293 (values (incf (box-count one
)) (incf (box-count two
)) (incf (box-count three
))))
1294 (defun no-optimizing-away-closure-two ()
1295 (setf one
(make-box)
1299 ;;; PowerPC safepoint builds occasionally hang or busy-loop (or
1300 ;;; sometimes run out of memory) in the following test. For developers
1301 ;;; interested in debugging this combination of features, it might be
1302 ;;; fruitful to concentrate their efforts around this test...
1304 (with-test (:name
(:funcallable-instances
)
1305 :broken-on
(or :win32
1307 (not :c-stack-is-control-stack
))))
1308 ;; the funcallable-instance implementation used not to be threadsafe
1309 ;; against setting the funcallable-instance function to a closure
1310 ;; (because the code and lexenv were set separately).
1311 (let ((fun (sb-kernel:%make-funcallable-instance
0))
1313 (setf (sb-kernel:funcallable-instance-fun fun
) #'closure-one
)
1315 (loop (setf (sb-kernel:funcallable-instance-fun fun
) #'closure-one
)
1316 (setf (sb-kernel:funcallable-instance-fun fun
) #'closure-two
)))
1318 (handler-case (loop (funcall fun
))
1319 (serious-condition (c) (setf condition c
)))))
1320 (let ((changer (make-thread #'changer
))
1321 (test (make-thread #'test
)))
1324 ;; The two closures above are fairly carefully crafted
1325 ;; so that if given the wrong lexenv they will tend to
1326 ;; do some serious damage, but it is of course difficult
1327 ;; to predict where the various bits and pieces will be
1328 ;; allocated. Five seconds failed fairly reliably on
1329 ;; both my x86 and x86-64 systems. -- CSR, 2006-09-27.
1330 (sb-ext:with-timeout
5
1331 (wait-for-threads (list test
)))
1332 (error "~@<test thread got condition:~2I~_~A~@:>" condition
))
1334 (terminate-thread changer
)
1335 (terminate-thread test
)
1336 (wait-for-threads (list changer test
))))))))
1338 (defun random-type (n)
1339 `(integer ,(random n
) ,(+ n
(random n
))))
1341 (defun subtypep-hash-cache-test ()
1343 (let ((type1 (random-type 500))
1344 (type2 (random-type 500)))
1345 (let ((a (subtypep type1 type2
)))
1347 (assert (eq (subtypep type1 type2
) a
))))))
1351 (with-test (:name
(:hash-cache subtypep
))
1353 ;; this didn't "reliably fail" with a small number of threads.
1354 ;; 30 is a compromise between running time and confidence in the result.
1356 collect
(make-thread #'subtypep-hash-cache-test
)))
1359 ;;;; BLACK BOX TESTS
1361 (in-package :cl-user
)
1362 (use-package :test-util
)
1363 (use-package "ASSERTOID")
1366 (with-test (:name
(:parallel defclass
))
1367 (write-line "WARNING, WILL HANG ON FAILURE!")
1368 (defclass test-1
() ((a :initform
:orig-a
)))
1369 (defclass test-2
() ((b :initform
:orig-b
)))
1370 (defclass test-3
(test-1 test-2
) ((c :initform
:orig-c
)))
1371 ;; This test is more likely to pass on Windows with the FORCE-OUTPUT
1372 ;; calls disabled in the folloving code. (As seen on a Server 2012
1373 ;; installation.) Clearly, this sort of workaround in a test is
1374 ;; cheating, and might be hiding the underlying bug that the test is
1375 ;; exposing. Let's review this later.
1377 (d1 (sb-thread:make-thread
(lambda ()
1379 do
(defclass test-1
() ((a :initform
:new-a
)))
1381 #-win32
(force-output)))
1383 (d2 (sb-thread:make-thread
(lambda ()
1385 do
(defclass test-2
() ((b :initform
:new-b
)))
1387 #-win32
(force-output)))
1389 (d3 (sb-thread:make-thread
(lambda ()
1391 do
(defclass test-3
(test-1 test-2
) ((c :initform
:new-c
)))
1393 #-win32
(force-output)))
1395 (i (sb-thread:make-thread
(lambda ()
1397 do
(let ((i (make-instance 'test-3
)))
1398 (assert (member (slot-value i
'a
) '(:orig-a
:new-a
)))
1399 (assert (member (slot-value i
'b
) '(:orig-b
:new-b
)))
1400 (assert (member (slot-value i
'c
) '(:orig-c
:new-c
))))
1402 #-win32
(force-output)))
1404 (format t
"~%sleeping!~%")
1406 (format t
"~%stopping!~%")
1409 (sb-thread:join-thread th
)
1410 (format t
"~%joined ~S~%" (sb-thread:thread-name th
)))
1414 (with-test (:name
(:deadlock-detection
:interrupts
)
1416 (let* ((m1 (sb-thread:make-mutex
:name
"M1"))
1417 (m2 (sb-thread:make-mutex
:name
"M2"))
1418 (t1-can-go (sb-thread:make-semaphore
:name
"T1 can go"))
1419 (t2-can-go (sb-thread:make-semaphore
:name
"T2 can go"))
1420 (t1 (sb-thread:make-thread
1422 (sb-thread:with-mutex
(m1)
1423 (sb-thread:wait-on-semaphore t1-can-go
)
1426 (t2 (sb-thread:make-thread
1428 (sb-ext:wait-for
(eq t1
(sb-thread:mutex-owner m1
)))
1429 (sb-thread:with-mutex
(m1 :wait-p t
)
1430 (sb-thread:wait-on-semaphore t2-can-go
)
1433 (sb-ext:wait-for
(eq m1
(sb-thread::thread-waiting-for t2
)))
1434 (sb-thread:interrupt-thread t2
(lambda ()
1435 (sb-thread:with-mutex
(m2 :wait-p t
)
1437 (eq m2
(sb-thread::thread-waiting-for t1
)))
1438 (sb-thread:signal-semaphore t2-can-go
))))
1439 (sb-ext:wait-for
(eq t2
(sb-thread:mutex-owner m2
)))
1440 (sb-thread:interrupt-thread t1
(lambda ()
1441 (sb-thread:with-mutex
(m2 :wait-p t
)
1442 (sb-thread:signal-semaphore t1-can-go
))))
1443 ;; both threads should finish without a deadlock or deadlock
1445 (let ((res (list (sb-thread:join-thread t1
)
1446 (sb-thread:join-thread t2
))))
1447 (assert (equal '(:ok1
:ok2
) res
)))))
1449 (with-test (:name
(:deadlock-detection
:gc
))
1450 ;; To semi-reliably trigger the error (in SBCL's where)
1451 ;; it was present you had to run this for > 30 seconds,
1452 ;; but that's a bit long for a single test.
1453 (let* ((stop (+ 5 (get-universal-time)))
1454 (m1 (sb-thread:make-mutex
:name
"m1"))
1455 (t1 (sb-thread:make-thread
1457 (loop until
(> (get-universal-time) stop
)
1458 do
(sb-thread:with-mutex
(m1)
1459 (eval `(make-array 24))))
1461 (t2 (sb-thread:make-thread
1463 (loop until
(> (get-universal-time) stop
)
1464 do
(sb-thread:with-mutex
(m1)
1465 (eval `(make-array 24))))
1467 (let ((res (list (sb-thread:join-thread t1
)
1468 (sb-thread:join-thread t2
))))
1469 (assert (equal '(:ok
:ok
) res
)))))
1471 (with-test (:name
:spinlock-api
)
1472 (handler-bind ((warning #'error
))
1473 (destructuring-bind (with make get release
)
1475 (list (compile nil
`(lambda (lock)
1476 (sb-thread::with-spinlock
(lock)
1478 (compile nil
`(lambda ()
1479 (sb-thread::make-spinlock
:name
"foo")))
1480 (compile nil
`(lambda (lock)
1481 (sb-thread::get-spinlock lock
)))
1482 (compile nil
`(lambda (lock)
1483 (sb-thread::release-spinlock lock
))))
1484 early-deprecation-warning
4)
1485 (let ((lock (funcall make
)))
1487 (funcall release lock
)
1488 (assert (eq t
(funcall with lock
)))))))
1490 (with-test (:name
:interrupt-io-unnamed-pipe
1495 (let ((stream (sb-sys:make-fd-stream fd
1496 :element-type
:default
1497 :serve-events nil
)))
1499 (let ((ok (handler-case
1510 (format *trace-output
* "~&=> ~A~%" ok
)
1511 (force-output *trace-output
*))))
1513 (ignore-errors (close stream
))))
1516 (multiple-value-bind (read write
)
1518 (let* ((reader (sb-thread:make-thread
(lambda () (reader read
))))
1519 (stream (sb-sys:make-fd-stream write
1521 :element-type
:default
1525 (sb-thread:interrupt-thread reader
(lambda ()
1531 (write-char #\x stream
)
1533 (sb-thread:join-thread reader
)))))
1535 (assert (eq result
:ok
))))
1537 (with-test (:name
:thread-alloca
)
1538 (sb-ext:run-program
"sh"
1539 '("run-compiler.sh" "-sbcl-pic" "-sbcl-shared"
1540 "alloca.c" "-o" "alloca.so")
1542 (load-shared-object (truename "alloca.so"))
1544 (alien-funcall (extern-alien "alloca_test" (function void
)))
1545 (sb-thread:join-thread
1546 (sb-thread:make-thread
1548 (alien-funcall (extern-alien "alloca_test" (function void
)))))))
1550 (with-test (:name
:fp-mode-inheritance-threads
)
1551 (labels ((fp-mode ()
1552 (let ((reserved-bits #+x86
(ash #b1110000011000000
16)
1554 (logandc2 (dpb 0 sb-vm
::float-sticky-bits
(sb-vm:floating-point-modes
))
1557 (let* ((fp-mode (fp-mode))
1559 (sb-thread:join-thread
1560 (sb-thread:make-thread
1563 (assert (= fp-mode thread-fp-mode
)))))
1565 (sb-int:with-float-traps-masked
(:divide-by-zero
)
1567 (setf (sb-vm:floating-point-modes
)
1568 (dpb sb-vm
:float-divide-by-zero-trap-bit
1569 sb-vm
::float-traps-byte
1570 (sb-vm:floating-point-modes
)))