5 Struct THREAD_POOL
gullradriel edited this page 2026-10-09 00:55:18 +02:00

THREAD_POOL

Module: THREADS: tools to create and manage a thread pool

Structure of a thread pool.

#include "n_thread_pool.h"

Public Attributes

Name
LIST * waiting_list
Waiting list handling.
THREAD_POOL_NODE ** thread_list
Dynamically allocated but fixed size thread array.
sem_t nb_tasks
semaphore signaling pool idle state: value 0 = work in progress, value 1 = pool is idle (no active threads, empty waiting list).
size_t nb_max_waiting
Maximum number of waiting procedures in the list, 0 for unlimited.
size_t nb_actives
number of threads actually doing a proc
size_t max_threads
Maximum number of running threads in the list.
pthread_mutex_t lock
mutex to prevent mutual access of waiting_list parameters
void(*)(void *param) discard
Called by destroy_threaded_pool() with the param of every queued job it discards without running, so the caller can release it.

Public Attributes Documentation

variable waiting_list

LIST * waiting_list;

Waiting list handling.

variable thread_list

THREAD_POOL_NODE ** thread_list;

Dynamically allocated but fixed size thread array.

variable nb_tasks

sem_t nb_tasks;

semaphore signaling pool idle state: value 0 = work in progress, value 1 = pool is idle (no active threads, empty waiting list).

Consumed by add_threaded_process and posted back only by refresh_thread_pool, so wait_for_threaded_pool() polls refresh rather than blocking on it.

variable nb_max_waiting

size_t nb_max_waiting;

Maximum number of waiting procedures in the list, 0 for unlimited.

variable nb_actives

size_t nb_actives;

number of threads actually doing a proc

variable max_threads

size_t max_threads;

Maximum number of running threads in the list.

variable lock

pthread_mutex_t lock;

mutex to prevent mutual access of waiting_list parameters

variable discard

void(*)(void *param) discard;

Called by destroy_threaded_pool() with the param of every queued job it discards without running, so the caller can release it.

NULL by default: the params are then left alone and only counted in the log. Set with set_thread_pool_discard().