1 #-sb-thread
(invoke-restart 'run-tests
::skip-file
)
3 (use-package "SB-THREAD")
5 ;;; This test takes at least 6 seconds because each thread wants to
6 ;;; grab and hold the mutex for a total of 3 seconds.
7 (with-test (:name
(:mutex
:contention
))
8 (let ((mutex (make-mutex :name
"contended")))
10 (let ((me *current-thread
*))
14 (assert (eql (mutex-owner mutex
) me
)))
15 (assert (not (eql (mutex-owner mutex
) me
))))
16 (format t
"done ~A~%" *current-thread
*))))
17 (let ((kid1 (make-thread #'run
))
18 (kid2 (make-thread #'run
)))
19 (format t
"contention ~A ~A~%" kid1 kid2
)
20 (wait-for-threads (list kid1 kid2
))))))
22 (with-test (:name
(interrupt-thread :interrupt-mutex-acquisition
)
24 (let ((lock (make-mutex :name
"loctite"))
27 (setf child
(test-interrupt
30 (assert (eql (mutex-owner lock
) *current-thread
*)))
31 (assert (not (eql (mutex-owner lock
) *current-thread
*)))
33 ;;hold onto lock for long enough that child can't get it immediately
35 (interrupt-thread child
(lambda () (format t
"l ~A~%" (mutex-owner lock
))))
36 (format t
"parent releasing lock~%"))
37 (process-all-interrupts child
)
38 (terminate-thread child
)
39 (wait-for-threads (list child
))))