File: join-thread-timeout.impure.lisp

package info (click to toggle)
sbcl 2%3A2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 52,008 kB
  • sloc: lisp: 535,135; ansic: 42,629; sh: 5,737; asm: 2,406; pascal: 717; makefile: 432; python: 56; cpp: 27
file content (22 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(use-package "SB-THREAD")

(with-test (:name (:join-thread :timeout)
            :skipped-on (or (not :sb-thread) :gc-stress))
  (macrolet ((delta-t () '(/ (- (get-internal-real-time) begin)
                             internal-time-units-per-second)))
    (let ((thr (sb-thread:make-thread (lambda () (sleep 10)) :name "thr1"))
          (begin (get-internal-real-time)))
      (assert-error(join-thread thr :timeout 0.01) join-thread-error)
      ;; should not have taken more than 1 sec. (and that's being generous)
      (assert (< (delta-t) 1))
      (sb-thread:terminate-thread thr))
    (let ((cookie (cons t t))
          (thr (sb-thread:make-thread (lambda () (sleep 10)) :name "thr2"))
          (begin (get-internal-real-time)))
      (assert (eq cookie (join-thread thr :timeout 0.01 :default cookie)))
      (assert (< (delta-t) 1))
      (sb-thread:terminate-thread thr)))
  ;; KLUDGE: JOIN-THREAD would signal an error if the victim threads already indicated
  ;; "aborted" status (by failing to store a list of values), so just give them time
  ;; to relax and unwind and remove themselves from *ALL-THREADS*
  (sleep .25))