Just a simple threadpool, based on C11 which uses the new threads.h library.
A basic fixed size, circular buffer queue with enqueue and dequeue functions.
Function | Description |
---|---|
queue_t *queue_create(size_t capacity, size_t element_size) | Creates a queue with the specified capacity and a size for each element. Returns the queue created. |
int queue_enqueue(queue_t *queue, void *item, size_t item_size) | Enqueue an item with a specified size and block if the queue is full. Returns -1 on error, 0 on success. |
int queue_dequeue(queue_t *queue, void *dest) | Dequeue an item. Returns -1 on error, 0 on success. |
void queue_free(queue_t *queue) | Free the queue back to the heap. |
A very simple threadpool which uses basic enqueue and join functions.
Function | Description |
---|---|
threadpool_t* threadpool_create(size_t worker_count, size_t queuesize) | Creates a threadpool with the specified number of workers and queuesize. Returns the threadpool created. |
void threadpool_enqueue(threadpool_t *threadpool, void (*fn)(void*), void *arg) | Enqueue an action to the threadpool's internal queue. |
void threadpool_join(threadpool_t *threadpool) | Wait for all threads in the thread pool to finish, and all tasks in the internal queue to be handled. |
void threadpool_free(threadpool_t *threadpool) | Free the threadpool back to the heap. |
This C11 threadpool implementation is licensed under the MIT license.