Rework thread pools
Allow the thread pool to vary in size by basing it on a resource pool of fixed size thread pools, which are similar to the previous thread pool implementation. Fixed size thread pools don't require fibers, but thread pools now do. Some procedures work with either thread pool implementation.
This commit is contained in:
parent
7ba77010ae
commit
016f37f108
2 changed files with 360 additions and 419 deletions
|
@ -6,10 +6,47 @@
|
|||
(knots thread-pool))
|
||||
|
||||
(let ((thread-pool
|
||||
(make-thread-pool 2)))
|
||||
(make-fixed-size-thread-pool 2)))
|
||||
|
||||
(assert-equal
|
||||
(call-with-thread
|
||||
thread-pool
|
||||
(lambda ()
|
||||
4))
|
||||
4))
|
||||
|
||||
(let ((thread-pool
|
||||
(make-fixed-size-thread-pool
|
||||
2
|
||||
#:thread-initializer (const '(2)))))
|
||||
|
||||
(assert-equal
|
||||
(call-with-thread
|
||||
thread-pool
|
||||
(lambda (num)
|
||||
(* 2 num)))
|
||||
4))
|
||||
|
||||
(let ((thread-pool
|
||||
(make-fixed-size-thread-pool 2)))
|
||||
|
||||
(assert-equal
|
||||
#t
|
||||
(with-exception-handler
|
||||
(lambda (exn)
|
||||
(knots-exception? exn))
|
||||
(lambda ()
|
||||
(call-with-thread
|
||||
thread-pool
|
||||
(lambda ()
|
||||
(+ 1 'a))))
|
||||
#:unwind? #t)))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let ((thread-pool
|
||||
(make-thread-pool 2)))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
(call-with-thread
|
||||
thread-pool
|
||||
|
@ -17,13 +54,13 @@
|
|||
4))
|
||||
4))))
|
||||
|
||||
(let ((thread-pool
|
||||
(make-thread-pool
|
||||
2
|
||||
#:thread-initializer (const '(2)))))
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let ((thread-pool
|
||||
(make-thread-pool
|
||||
2
|
||||
#:thread-initializer (const '(2)))))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
(call-with-thread
|
||||
thread-pool
|
||||
|
@ -31,22 +68,11 @@
|
|||
(* 2 num)))
|
||||
4))))
|
||||
|
||||
(let ((process-job
|
||||
count-jobs
|
||||
count-threads
|
||||
list-jobs
|
||||
(create-work-queue
|
||||
2
|
||||
(lambda (i)
|
||||
(* i 2)))))
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let ((thread-pool
|
||||
(make-thread-pool 2)))
|
||||
|
||||
(process-job 3))
|
||||
|
||||
(let ((thread-pool
|
||||
(make-thread-pool 2)))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
#t
|
||||
(with-exception-handler
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue