Simple threadpool implementation in C using POSIX pthread library.
create_threadpool(int num_threads)
add_threadpool_work(void* func(), void *arg)
This will enqueue the function for execution by the first available thread in the pool. By definition all the pushed functions are assumed to be independent and threadsafe among each other (i.e. no global variables or common pointers).
As a side effect the threadpool will call free(arg) after executing the function.
destroy_thredpool()
Will wait for threads to finish current function execution and free queue memory afterwards.
See /example/ for use case
To build run:
make all
The library and example illustrate the following key concepts: signal handling, thread, condition variables, mutex, spin lock, linkedlist, dynamic memory allocation and freeing.