No matching definitions.

tur/threadpool

stdlib/threadpool.tur

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

Since: Phase T20-B

defopaque

WorkQueueHandle

(WorkQueueHandle)
defopaque

ThreadPoolHandle

(ThreadPoolHandle)
defopaque

DynThreadPoolHandle

(DynThreadPoolHandle)
defopaque

FutureHandle

(FutureHandle)
defn

work-queue-new

(work-queue-new :)

create a new unbounded work queue that grows dynamically.

A WorkQueueHandle to the WorkQueueBlock.

(let [q (work-queue-new)] ...)  ; => WorkQueueHandle

Since: Phase T20-B

defn

work-queue-new-bounded

(work-queue-new-bounded [cap : int] :)

create a new bounded work queue with a fixed capacity.

capmaximum number of items the queue can hold; push blocks when full

A WorkQueueHandle to the WorkQueueBlock.

(let [q (work-queue-new-bounded 64)] ...)  ; => WorkQueueHandle

Since: Phase T20-B

defn

work-queue-push

(work-queue-push [q : WorkQueueHandle v : int] :)

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 : WorkQueueHandle] :)

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 : WorkQueueHandle] :)

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 : WorkQueueHandle] :)

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>] :)

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] :)

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

nnumber of worker threads to spawn (must be > 0)

A ThreadPoolHandle to the ThreadPoolBlock.

(let [tp (thread-pool-new 4)] ...)  ; => ThreadPoolHandle

Since: Phase T20-D

defn

thread-pool-submit

(thread-pool-submit [tp : ThreadPoolHandle task_fn ptr<void> task_arg 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 FutureHandle to a FutureCell that is fulfilled with task_fn's return value.

(let [fut (thread-pool-submit tp my-fn arg)] ...)  ; => FutureHandle

Since: Phase T20-D

defn

thread-pool-shutdown

(thread-pool-shutdown [tp : ThreadPoolHandle] :)

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 : ThreadPoolHandle] :)

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] :)

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

A DynThreadPoolHandle to the DynThreadPoolBlock.

(let [tp (thread-pool-new-dynamic 2 8)] ...)  ; => DynThreadPoolHandle

Since: Phase T20-D

defn

tp-dyn-worker

(tp-dyn-worker [arg 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 : DynThreadPoolHandle task_fn ptr<void> task_arg 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 FutureHandle to a FutureCell fulfilled with task_fn's return value.

(let [fut (thread-pool-dynamic-submit tp my-fn arg)] ...)  ; => FutureHandle

Since: Phase T20-D

defn

thread-pool-dynamic-shutdown

(thread-pool-dynamic-shutdown [tp : DynThreadPoolHandle] :)

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 : DynThreadPoolHandle] :)

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