No matching definitions.

tur/threadpool

stdlib/threadpool.tur

WorkQueue<T> and ThreadPool for task-based parallelism.

Since: Phase T20-B

defn

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

defn

work-queue-new-bounded

(work-queue-new-bounded [cap :int] :ptr<void>)

create a new bounded work queue with a fixed capacity.

capmaximum 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

defn

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.

qqueue handle returned by work-queue-new or work-queue-new-bounded
vint64_t value to enqueue
(work-queue-push q 42)

Since: Phase T20-B

defn

work-queue-pop

(work-queue-pop [q :ptr<void>] :int)

pop a value from the work queue, blocking until one is available.

qqueue 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

defn

work-queue-close

(work-queue-close [q :ptr<void>] :nil)

close the work queue, waking all blocked producers and consumers.

qqueue handle returned by work-queue-new or work-queue-new-bounded
(work-queue-close q)

Since: Phase T20-B

defn

work-queue-free

(work-queue-free [q :ptr<void>] :nil)

destroy a work queue and release all associated memory.

qqueue handle returned by work-queue-new or work-queue-new-bounded
(work-queue-free q)

Since: Phase T20-B

defn

tp-worker

(tp-worker [arg :ptr<void>] :ptr<void>)

internal worker thread function for a fixed ThreadPool.

argptr<void> pointing to the ThreadPoolBlock

NULL on exit.

Since: Phase T20-D

defn

thread-pool-new

(thread-pool-new [n :int] :ptr<void>)

create a fixed-size thread pool with n worker threads.

nnumber 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

defn

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.

tpthread pool handle returned by thread-pool-new
task_fnC function pointer (void *(*)(void *)) to execute on a worker
task_argopaque 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

defn

thread-pool-shutdown

(thread-pool-shutdown [tp :ptr<void>] :nil)

signal all workers to stop and join them.

tpthread pool handle returned by thread-pool-new
(thread-pool-shutdown tp)

Since: Phase T20-D

defn

thread-pool-free

(thread-pool-free [tp :ptr<void>] :nil)

free the thread pool (must be called after shutdown).

tpthread pool handle returned by thread-pool-new
(thread-pool-free tp)

Since: Phase T20-D

defn

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_threadsinitial number of worker threads to spawn (must be > 0)
max_threadsupper 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

defn

tp-dyn-worker

(tp-dyn-worker [arg :ptr<void>] :ptr<void>)

internal worker thread function for a dynamic ThreadPool.

argptr<void> pointing to the DynThreadPoolBlock

NULL on exit.

Since: Phase T20-D

defn

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.

tpdynamic thread pool handle returned by thread-pool-new-dynamic
task_fnC function pointer (void *(*)(void *)) to execute on a worker
task_argopaque 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

defn

thread-pool-dynamic-shutdown

(thread-pool-dynamic-shutdown [tp :ptr<void>] :nil)

signal all dynamic pool workers to stop and join them.

tpdynamic thread pool handle returned by thread-pool-new-dynamic
(thread-pool-dynamic-shutdown tp)

Since: Phase T20-D

defn

thread-pool-dynamic-free

(thread-pool-dynamic-free [tp :ptr<void>] :nil)

free a dynamic thread pool (must be called after shutdown).

tpdynamic thread pool handle returned by thread-pool-new-dynamic
(thread-pool-dynamic-free tp)

Since: Phase T20-D