1.0.5.9: experimental semi-synchronous deadlines
[sbcl.git] / tests / deadline.impure.lisp
1 (defmacro assert-timeout (form)
2   (let ((ok (gensym "OK")))
3     `(let ((,ok ',ok))
4        (unless (eq ,ok
5                    (handler-case ,form
6                      (timeout ()
7                        ,ok)))
8          (error "No timeout from form:~%  ~S" ',form)))))
9
10
11 (assert-timeout
12  (sb-impl::with-deadline (:seconds 1)
13    (run-program "sleep" '("5") :search t :wait t)))
14
15 #+(and sb-thread (not sb-lutex))
16 (progn
17   (assert-timeout
18    (let ((lock (sb-thread:make-mutex)))
19      (sb-thread:make-thread (lambda () (sb-thread:get-mutex lock) (sleep 5)))
20      (sb-impl::with-deadline (:seconds 1)
21        (sb-thread:get-mutex lock))))
22
23   (assert-timeout
24    (let ((sem (sb-thread::make-semaphore :count 0)))
25      (sb-impl::with-deadline (:seconds 1)
26        (sb-thread::wait-on-semaphore sem))))
27
28   (assert-timeout
29    (sb-impl::with-deadline (:seconds 1)
30      (sb-thread:join-thread
31       (sb-thread:make-thread (lambda () (loop (sleep 1))))))))