paul_threads.h
IntroductionCross-platform thread pool and job queue implementation for C/C++. DiscussionImplementation is included when PAUL_THREADS_IMPLEMENTATION or PAUL_IMPLEMENTATION is defined.
Functions
thrd_pool_createCreate a thread pool thrd_pool_t* thrd_pool_create( size_t num_threads, size_t max_queue_size); ParametersReturn ValueReturns a pointer to the created thread pool, or NULL on failure thrd_pool_destroyDestroy the thread pool void thrd_pool_destroy( thrd_pool_t *pool); Parametersthrd_pool_get_active_countGet the number of active threads in the thread pool size_t thrd_pool_get_active_count( thrd_pool_t *pool); ParametersReturn ValueReturns the number of active threads thrd_pool_get_queue_sizeGet the size of the job queue in the thread pool size_t thrd_pool_get_queue_size( thrd_pool_t *pool); ParametersReturn ValueReturns the size of the job queue thrd_pool_get_thread_countGet the number of threads in the thread pool size_t thrd_pool_get_thread_count( thrd_pool_t *pool); ParametersReturn ValueReturns the number of threads in the pool thrd_pool_submitSubmit a job to the thread pool int thrd_pool_submit( thrd_pool_t *pool, void (*function)( void*), void *arg, void (*cleanup)( void*)); ParametersReturn ValueReturns thrd_success on success, thrd_error on failure thrd_pool_waitWait for all jobs in the thread pool to complete void thrd_pool_wait( thrd_pool_t *pool); ParametersTypedefsjob_node_ttypedef struct job_node { job_t job; struct job_node *next; } job_node_t; FieldsDiscussionNode structure for the job queue job_queue_ttypedef struct job_queue { job_node_t *head; job_node_t *tail; mtx_t mutex; cnd_t not_empty; size_t size; size_t max_size; bool shutdown; } job_queue_t; Fields
DiscussionJob queue structure for thread pool job_ttypedef struct job { void (*function)( void *arg); void *arg; void (*cleanup)( void *arg); // Optional cleanup function } job_t; FieldsDiscussionJob structure for thread pool tasks thrd_pool_ttypedef struct { thrd_t *threads; size_t num_threads; job_queue_t job_queue; atomic_bool shutdown; atomic_size_t active_threads; mtx_t pool_mutex; cnd_t all_threads_idle; } thrd_pool_t; Fields
DiscussionThread pool structure |