Skip to content
Snippets Groups Projects
Commit faf4bfdf authored by Christopher Baines's avatar Christopher Baines
Browse files

Enable make-worker-thread-channel to create multiple worker threads.

This will allow running multiple threads, that all listen on the same channel,
enabling processing multiple jobs at one time.

* src/cuirass/utils.scm (make-worker-thread-channel): Add a #:parallelism
argument, and create as many threads as the given parallelism.
parent e34d773f
No related branches found
No related tags found
No related merge requests found
......@@ -99,20 +99,24 @@ delimited continuations and fibers."
(define %worker-thread-args
(make-parameter #f))
(define (make-worker-thread-channel initializer)
(define* (make-worker-thread-channel initializer
#:key (parallelism 1))
"Return a channel used to offload work to a dedicated thread. ARGS are the
arguments of the worker thread procedure."
(parameterize (((@@ (fibers internal) current-fiber) #f))
(let ((channel (make-channel)))
(let ((args (initializer)))
(call-with-new-thread
(lambda ()
(parameterize ((%worker-thread-args args))
(let loop ()
(match (get-message channel)
(((? channel? reply) . (? procedure? proc))
(put-message reply (apply proc args))))
(loop))))))
(for-each
(lambda _
(let ((args (initializer)))
(call-with-new-thread
(lambda ()
(parameterize ((%worker-thread-args args))
(let loop ()
(match (get-message channel)
(((? channel? reply) . (? procedure? proc))
(put-message reply (apply proc args))))
(loop)))))))
(iota parallelism))
channel)))
(define (call-with-worker-thread channel proc)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment