Q-THREAD-POOL API DOCUMENTATION Max Rottenkolber Friday, 16 April 2021 Table of Contents 1 q-thread-pool 1.1 Example Usage 1.2 destroy-thread-pool (Function) 1.3 enqueue-task (Macro) 1.4 make-thread-pool (Function) 1 q-thread-pool Simple thread pools based on concurrent queues. 1.1 Example Usage Use make-thread-pool to create a thread pool with 16 threads and a backlog of 32 and bind it to pool. (setq pool (make-thread-pool 16 32)) Use enqueue-task to enqueue 64 tasks for parallel evaluation by pool. Note that the body forms of enqueue-task is a lexical closure. The threads of pool will work off the backlog concurrently. Once the backlog is full, e.g. when there are already 32 other tasks waiting, enqueue-task will block until there is room in the queue. (let ((out *standard-output*)) (dotimes (i 64) (enqueue-task pool (sleep 5) (write-string "x" out)))) When pool is no longer needed, its threads should be destroy using destroy-thread-pool in order to avoid leaking resources. (destroy-thread-pool pool) 1.2 destroy-thread-pool (Function) Syntax: — Function: destroy-thread-pool thread-pool Arguments and Values: thread-pool—a thread pool. Description: destroy-thread-pool destroys all threads allocated by thread-pool. 1.3 enqueue-task (Macro) Syntax: — Macro: enqueue-task thread-pool &body forms Arguments and Values: thread-pool—a thread pool. forms—forms. Description: enqueue-task enqueues a lexical closure containing forms for evaluation by thread-pool. If the backlog of of thread-pool is full enqueue-task will block until another task is dequeued. 1.4 make-thread-pool (Function) Syntax: — Function: make-thread-pool size backlog Arguments and Values: size, backlog—positive integers. Description: make-thread-pool returns a thread pool. Size is the number of threads in the pool. Backlog is the number of tasks that will be queued before enqueue-task blocks.