The thread pool uses POSIX threads, so compile using the -lpthread flag.
gcc example.c thrpl.c -lpthread -o example && ./exampleDebug mode:
gcc example.c thrpl.c -lpthread -DTHRPL_DEBUG -o example && ./examplegit clone https://github.com/zaiic/thrpl.c
cd thrpl.cPut thrpl.c and thrpl.h in your project or generate a header-only file and put it in your project.
Generate header-only file:
./generate_header_only.shNotice: The header-only file is stb style.
Don't forget to put #define THRPL_IMLEMENTATION in your file before including header-only file.
#define THRPL_IMLEMENTATION
#include "thrpl.h" // header-only file| Function | Description | 
|---|---|
| ThreadPool *ThreadPool_new() | Create a new thread pool and return a pointer to it. | 
| int ThreadPool_add_task(ThreadPool *self, Task task) | Add a task to the thread pool. | 
| int ThreadPool_gracefully_destroy(ThreadPool *self) | Destroy the thread pool when the task queue is empty. | 
| int ThreadPool_destroy(ThreadPool *self) | Destroy the thread pool. | 
typedef void *(*function)(void *);
typedef struct {
  function func;
  void *argv;
} Task;