thread_pool.h – thread pool¶
Thread pool¶
-
type thread_pool_t¶
This is a thread pool.
-
type thread_pool_handle¶
This is a handle to a thread in a thread pool.
-
void thread_pool_init(thread_pool_t T, slong size)¶
Initialise
Tand createsizesleeping threads that are available to work. If \(size \le 0\) no threads are created and future calls tothread_pool_request()will return \(0\) (unlessthread_pool_set_size()has been called).
-
slong thread_pool_get_size(thread_pool_t T)¶
Return the number of threads in
T.
-
int thread_pool_set_size(thread_pool_t T, slong new_size)¶
If all threads in
Tare in the available state, resizeTand return 1. Otherwise, return0.
-
slong thread_pool_request(thread_pool_t T, thread_pool_handle *out, slong requested)¶
Put at most
requestedthreads in the unavailable state and return their handles. The handles are written tooutand the number of handles written is returned. These threads must be released by a call tothread_pool_give_back.
-
void thread_pool_wake(thread_pool_t T, thread_pool_handle i, int max_workers, void (*f)(void*), void *a)¶
Wake up a sleeping thread
iand have it work onf(a). The thread being woken will be allowed to startmax_workersadditional worker threads. Usually this value should be set to0.
-
void thread_pool_wait(thread_pool_t T, thread_pool_handle i)¶
Wait for thread
ito finish working and go back to sleep.
-
void thread_pool_give_back(thread_pool_t T, thread_pool_handle i)¶
Put thread
iback in the available state. This thread should be sleeping when this function is called.
-
void thread_pool_clear(thread_pool_t T)¶
Release any resources used by
T. All threads should be given back before this function is called.