This repository has been archived on 2022-08-10. You can view files and clone it, but cannot push or open issues or pull requests.
chez-openbsd/mats/thread-check.ss

23 lines
749 B
Scheme
Raw Normal View History

2022-07-29 15:12:07 +02:00
(define $threads (foreign-procedure "(cs)threads" () scheme-object))
(define $nthreads 1)
(define $yield
(let ([t (make-time 'time-duration 1000000 0)])
(lambda () (sleep t))))
(define $thread-check
(lambda ()
(let loop ([n 100] [nt (length ($threads))])
(cond
[(<= nt $nthreads)
(set! $nthreads nt)
(collect)]
[else
($yield)
(let* ([ls ($threads)] [nnt (length ls)])
(cond
[(< nnt nt) (loop n nnt)]
[(= n 0)
(set! $nthreads nnt)
(errorf #f "extra threads running ~s" ls)]
[else (loop (- n 1) nnt)]))]))
#t))