Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1.05 KB

File metadata and controls

50 lines (38 loc) · 1.05 KB

thread_pool

my thread_pool library writen in c

Installation:

Prerequisites:

  1. C compiler that supports C11 and thread.h + stdatomic.h
  2. CMake (version 3.10 or later)
  3. git

Clone repository:

git clone https://github.com/fogInSingularity/thread_pool.git

Navigate to the project directory:

cd thread_pool

Configure and build project:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel `nproc`

If you want to run tests: Configure and build project:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON
cmake --build build --parallel `nproc`

Usage(API):

typedef enum {
    ThreadPoolError_kOk            = 0,
    ThreadPoolError_kTaskQueueFull = 1,
} ThreadPoolError;

typedef struct ThreadPool ThreadPool;
typedef void (*TaskFunc)(void* task_arg);

ThreadPool* ThreadPoolCreate(size_t n_threads, size_t queue_size);
void ThreadPoolDestroy(ThreadPool* thread_pool);

ThreadPoolError ThreadPoolQueueTask(ThreadPool* thread_pool, TaskFunc task_func, void* task_arg);