45static pthread_mutex_t
count_lock = PTHREAD_MUTEX_INITIALIZER;
77static int run(
unsigned int delay) {
84 for (i = 0; i < 4; i++) {
85 int* p = malloc(
sizeof(
int));
108 fprintf(stderr,
"short budget: %d ran and %d discarded, wanted 1 and 3\n",
ran,
discarded);
114 fprintf(stderr,
"long budget: %d ran and %d discarded, wanted 4 and 0\n",
ran,
discarded);
118 fprintf(stderr,
"ex_thread_pool_discard: %d failure(s)\n",
failures);
121 printf(
"ex_thread_pool_discard: all checks passed\n");
static NETWORK_POOL * pool
static pthread_mutex_t count_lock
Guards the two counters.
static int ran
Jobs that ran, and params the discard function released.
static void * slow_job(void *p)
A job that takes 300 ms and releases its own param.
static void discard_job(void *p)
Discard function: releases a param that will never be run.
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_NULL
no log output
#define NORMAL_PROC
processing mode for added func, synced start, can be queued
THREAD_POOL * new_thread_pool(size_t nbmaxthr, size_t nb_max_waiting)
Create a new pool of nbmaxthr threads.
int add_threaded_process(THREAD_POOL *thread_pool, void *(*func_ptr)(void *param), void *param, int mode)
add a function and params to a thread pool
int destroy_threaded_pool(THREAD_POOL **pool, unsigned int delay)
Stop every thread of a pool and free it.
int set_thread_pool_discard(THREAD_POOL *thread_pool, void(*discard)(void *param))
Set what destroy_threaded_pool() does with the param of a queued job it discards.
Structure of a thread pool.
Common headers and low-level functions & define.