thread-pool/pool
bounded POSIX worker-thread pool with a typed,
Since: TP1 (typed/linear surface since TP2)
Pool
(Pool [T] :ptr<void>)
an opaque, linear worker-pool handle parameterised by its work-item
Since: TP2
pool-new
(pool-new [T])
allocate a bounded worker pool with a typed callback.
| size | number of worker threads (clamped to >= 1). | |
| callback | (fn [T] void) invoked on each dequeued item. Receives the | |
| item by value and owns it (the submitter loses access on | ||
| submit). Must remain valid for the full lifetime of the | ||
| pool | bind it in a scope that outlives pool-stop. |
A linear (Pool T) handle. pool-new aborts on the (rare) allocation / spawn failure rather than handing back a null linear handle.
(let [p (pool-new 8 (fn [x : int] : void (consume x)))]
(pool-submit p 1)
(pool-stop p))
Since: TP2
pool-submit
(pool-submit [T])
enqueue a typed work item; blocks when the ring is full.
| pool | borrowed (Pool T) handle. | |
| item | an owned T, handed to the worker callback. |
Since: TP2
pool-stop
(pool-stop [T])
signal shutdown, drain queued items, join workers, free.
| pool | the (Pool T) handle, consumed. |
Since: TP2
pool-try-submit
(pool-try-submit [T])
enqueue without blocking; report saturation instead.
| pool | borrowed (Pool T) handle. | |
| item | an owned T. |
Since: TP2
pool-pending
(pool-pending [T])
number of items currently queued (read under the lock).
Since: TP2
pool-workers
(pool-workers [T])
number of live worker threads.
Since: TP2
pool-queue-cap
(pool-queue-cap [T])
ring-buffer capacity (max(size * 4, 64)).
Since: TP2
pool-new-raw
(pool-new-raw [size : int callback ptr<void>] :)
allocate a pool driven by a raw `void (*)(void *item)` C
| size | worker count (clamped to >= 1). | |
| callback | ptr<void> holding a `void (*)(void *item)`. |
Since: TP2 (was pool-new in TP1)
pool-submit-raw
(pool-submit-raw [pool ptr<void> item ptr<void>] :)
enqueue a ptr<void> work item on a raw pool; blocks
Since: TP2 (was pool-submit in TP1)
pool-stop-raw
(pool-stop-raw [pool ptr<void>] :)
drain, join, and free a raw pool. NULL is a no-op.
Since: TP2 (was pool-stop in TP1)
Internal definitions
pool-worker-loop-- (internal) thread entry; dequeues and dispatches items.pool-try-enqueue