aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2025-01-13 12:22:27 +0000
committerChristopher Baines <mail@cbaines.net>2025-01-14 10:05:06 +0000
commitd572f591a3c136bfc7b23160e16381c92588f8d9 (patch)
treec50f02a2f1be1c50572a56dd2a7d7afa2fd59e97 /tests
parentdcb56ee2c5ac3e283cb46841766e7282f3c2c52e (diff)
downloadknots-d572f591a3c136bfc7b23160e16381c92588f8d9.tar
knots-d572f591a3c136bfc7b23160e16381c92588f8d9.tar.gz
Rename worker threads to thread pool
I think this needs more work, maybe the thread pool should be more similar to the resource pool, but I think the name change is still helpful. Maybe there's a need for a variable size thread pool and that can better integrate with the work queue.
Diffstat (limited to 'tests')
-rw-r--r--tests/thread-pool.scm44
-rw-r--r--tests/worker-threads.scm32
2 files changed, 44 insertions, 32 deletions
diff --git a/tests/thread-pool.scm b/tests/thread-pool.scm
new file mode 100644
index 0000000..71b4494
--- /dev/null
+++ b/tests/thread-pool.scm
@@ -0,0 +1,44 @@
+(use-modules (tests)
+ (srfi srfi-71)
+ (fibers)
+ (unit-test)
+ (knots thread-pool))
+
+(let ((thread-pool
+ (make-thread-pool 2)))
+
+ (run-fibers-for-tests
+ (lambda ()
+ (assert-equal
+ (call-with-thread
+ thread-pool
+ (lambda ()
+ 4))
+ 4))))
+
+(let ((thread-pool
+ (make-thread-pool
+ 2
+ #:thread-initializer (const '(2)))))
+
+ (run-fibers-for-tests
+ (lambda ()
+ (assert-equal
+ (call-with-thread
+ thread-pool
+ (lambda (num)
+ (* 2 num)))
+ 4))))
+
+(let ((process-job
+ count-jobs
+ count-threads
+ list-jobs
+ (create-work-queue
+ 2
+ (lambda (i)
+ (* i 2)))))
+
+ (process-job 3))
+
+(display "thread-pool test finished successfully\n")
diff --git a/tests/worker-threads.scm b/tests/worker-threads.scm
deleted file mode 100644
index cfdfbf8..0000000
--- a/tests/worker-threads.scm
+++ /dev/null
@@ -1,32 +0,0 @@
-(use-modules (tests)
- (srfi srfi-71)
- (fibers)
- (unit-test)
- (knots worker-threads))
-
-(let ((worker-thread-set
- (make-worker-thread-set
- (const '())
- #:parallelism 2)))
-
- (run-fibers-for-tests
- (lambda ()
- (assert-equal
- (call-with-worker-thread
- worker-thread-set
- (lambda ()
- 4))
- 4))))
-
-(let ((process-job
- count-jobs
- count-threads
- list-jobs
- (create-work-queue
- 2
- (lambda (i)
- (* i 2)))))
-
- (process-job 3))
-
-(display "worker-threads test finished successfully\n")