2017-08-27

(sph thread-pool)

thread-pool that uses wait-conditions to pause unused threads and has a customisable queue type

procedures can be added to a queue and are executed in the thread-pool by the next free thread

part of sph-lib

import name

(sph thread-pool)

exports

sph-thread-pool-description

variable

thread-pool-create

procedure

signature

[size exception-handler queue-type] ->

[integer procedure:{key retry ->} true/symbol/(symbol ...) list/symbol:lifo/fifo] -> (procedure:{procedure:nullary:code-to-execute -> any/false}:enqueue! thread ...)

description

creates a list of threads that wait using condition variables to execute procedures from a queue, which is a first-in-first-out queue by default.

the last-in-first-out queue just uses scheme lists and earlier tasks wait if there are not enough threads available to handle all tasks.

the returned enqueue! procedure can be used to add procedures to the queue.

if a procedure from the queue evaluates to false, the thread it was called in exits.

by adding as many procedures like this as there are threads in the pool,

all threads can be closed without having to cancel them by other more obscure means.

the default size is the current processor count.

queue-type can be a custom queue given as a list with the following signature

queue-type: (procedure:make-queue procedure:empty?:{queue -> boolean} procedure:enqueue:{queue a ->} procedure:dequeue:{queue -> any})

thread-pool-finish

procedure

signature

enqueue thread-list ->

(thread ...) -> (thread-exit-value ...)

description

let threads complete all currently enqueued tasks and exit


tags: programming guile documentation library scheme sph-lib q1 computer thread-pool highlight sph-thread-pool