Fix the destroy behaviour for fixed size thread pools
All checks were successful
/ test (push) Successful in 38s

destroy-thread-pool should block until the thread pool has been
destroyed.
This commit is contained in:
Christopher Baines 2026-03-18 09:34:00 +00:00
parent 09cb805ee2
commit db9b549e59
2 changed files with 50 additions and 14 deletions

View file

@ -1,5 +1,6 @@
(use-modules (tests)
(ice-9 atomic)
(ice-9 threads)
(srfi srfi-71)
(fibers)
(unit-test)
@ -142,4 +143,33 @@
ref-and-decrement))
(error)))
;; Test that the destructor is called when a size 1 fixed-size thread
;; pool is destroyed, and that destroy-thread-pool blocks until it has
;; completed.
(let* ((destructor-called? #f)
(thread-pool
(make-fixed-size-thread-pool
1
#:thread-destructor
(lambda ()
(set! destructor-called? #t)))))
(destroy-thread-pool thread-pool)
(assert-equal #t destructor-called?))
;; Test that the destructor is called for every thread when a
;; multi-thread fixed-size thread pool is destroyed, and that
;; destroy-thread-pool blocks until all destructors have completed.
(let* ((destructor-count 0)
(mutex (make-mutex))
(pool-size 3)
(thread-pool
(make-fixed-size-thread-pool
pool-size
#:thread-destructor
(lambda ()
(with-mutex mutex
(set! destructor-count (+ destructor-count 1)))))))
(destroy-thread-pool thread-pool)
(assert-equal pool-size destructor-count))
(display "thread-pool test finished successfully\n")