tur/threadpool
WorkQueue<T> and ThreadPool for task-based parallelism.
Since: Phase T20-B
work-queue-new
(work-queue-new :ptr<void>)
create a new unbounded work queue that grows dynamically.
An opaque ptr<void> handle to the WorkQueueBlock.
(let [q (work-queue-new)] ...) ; => ptr<void>
Since: Phase T20-B
work-queue-new-bounded
(work-queue-new-bounded [cap :int] :ptr<void>)
create a new bounded work queue with a fixed capacity.
| cap | maximum number of items the queue can hold; push blocks when full |
An opaque ptr<void> handle to the WorkQueueBlock.
(let [q (work-queue-new-bounded 64)] ...) ; => ptr<void>
Since: Phase T20-B
work-queue-push
(work-queue-push [q :ptr<void> v :int] :nil)
push a value onto the work queue, blocking if the queue is bounded and full.
| q | queue handle returned by work-queue-new or work-queue-new-bounded | |
| v | int64_t value to enqueue |
(work-queue-push q 42)
Since: Phase T20-B
work-queue-pop
(work-queue-pop [q :ptr<void>] :int)
pop a value from the work queue, blocking until one is available.
| q | queue handle returned by work-queue-new or work-queue-new-bounded |
The next int64_t value, or INT64_MIN if the queue is closed and empty.
(work-queue-pop q) ; => int (INT64_MIN signals shutdown)
Since: Phase T20-B
work-queue-close
(work-queue-close [q :ptr<void>] :nil)
close the work queue, waking all blocked producers and consumers.
| q | queue handle returned by work-queue-new or work-queue-new-bounded |
(work-queue-close q)
Since: Phase T20-B
work-queue-free
(work-queue-free [q :ptr<void>] :nil)
destroy a work queue and release all associated memory.
| q | queue handle returned by work-queue-new or work-queue-new-bounded |
(work-queue-free q)
Since: Phase T20-B
tp-worker
(tp-worker [arg :ptr<void>] :ptr<void>)
internal worker thread function for a fixed ThreadPool.
| arg | ptr<void> pointing to the ThreadPoolBlock |
NULL on exit.
Since: Phase T20-D
thread-pool-new
(thread-pool-new [n :int] :ptr<void>)
create a fixed-size thread pool with n worker threads.
| n | number of worker threads to spawn (must be > 0) |
An opaque ptr<void> handle to the ThreadPoolBlock.
(let [tp (thread-pool-new 4)] ...) ; => ptr<void>
Since: Phase T20-D
thread-pool-submit
(thread-pool-submit [tp :ptr<void> task_fn :ptr<void> task_arg :ptr<void>] :ptr<void>)
submit a task to the thread pool and return a Future.
| tp | thread pool handle returned by thread-pool-new | |
| task_fn | C function pointer (void *(*)(void *)) to execute on a worker | |
| task_arg | opaque argument forwarded to task_fn |
A ptr<void> to a FutureCell that is fulfilled with task_fn's return value.
(let [fut (thread-pool-submit tp my-fn arg)] ...) ; => ptr<void>
Since: Phase T20-D
thread-pool-shutdown
(thread-pool-shutdown [tp :ptr<void>] :nil)
signal all workers to stop and join them.
| tp | thread pool handle returned by thread-pool-new |
(thread-pool-shutdown tp)
Since: Phase T20-D
thread-pool-free
(thread-pool-free [tp :ptr<void>] :nil)
free the thread pool (must be called after shutdown).
| tp | thread pool handle returned by thread-pool-new |
(thread-pool-free tp)
Since: Phase T20-D
thread-pool-new-dynamic
(thread-pool-new-dynamic [min_threads :int max_threads :int] :ptr<void>)
create an auto-scaling thread pool between min and max threads.
| min_threads | initial number of worker threads to spawn (must be > 0) | |
| max_threads | upper bound on workers; new threads are added when all are busy |
An opaque ptr<void> handle to the DynThreadPoolBlock.
(let [tp (thread-pool-new-dynamic 2 8)] ...) ; => ptr<void>
Since: Phase T20-D
tp-dyn-worker
(tp-dyn-worker [arg :ptr<void>] :ptr<void>)
internal worker thread function for a dynamic ThreadPool.
| arg | ptr<void> pointing to the DynThreadPoolBlock |
NULL on exit.
Since: Phase T20-D
thread-pool-dynamic-submit
(thread-pool-dynamic-submit [tp :ptr<void> task_fn :ptr<void> task_arg :ptr<void>] :ptr<void>)
submit a task to the dynamic thread pool, scaling up if needed.
| tp | dynamic thread pool handle returned by thread-pool-new-dynamic | |
| task_fn | C function pointer (void *(*)(void *)) to execute on a worker | |
| task_arg | opaque argument forwarded to task_fn |
A ptr<void> to a FutureCell fulfilled with task_fn's return value.
(let [fut (thread-pool-dynamic-submit tp my-fn arg)] ...) ; => ptr<void>
Since: Phase T20-D
thread-pool-dynamic-shutdown
(thread-pool-dynamic-shutdown [tp :ptr<void>] :nil)
signal all dynamic pool workers to stop and join them.
| tp | dynamic thread pool handle returned by thread-pool-new-dynamic |
(thread-pool-dynamic-shutdown tp)
Since: Phase T20-D
thread-pool-dynamic-free
(thread-pool-dynamic-free [tp :ptr<void>] :nil)
free a dynamic thread pool (must be called after shutdown).
| tp | dynamic thread pool handle returned by thread-pool-new-dynamic |
(thread-pool-dynamic-free tp)
Since: Phase T20-D