Back to home

kronkpool

A simple thread pool in C using pthread.

Overview

Kronkpool is a simple thread pool written in C, using a custom queue and pthread (Win32 threads on Windows). You give it tasks and the workers share them.

It builds with CMake as a static or shared library, on Linux and Windows (MSVC, MinGW). Its API is four functions.

Examples

Run a task
#include <pthread.h>
#include <kronkpool/kronkpool.h>
#include <stdio.h>

static void *my_task(void *arg)
{
    printf("Task executed in thread [%zu] with arg [%p]\n", pthread_self(), arg);
    return NULL;
}

int main(void)
{
    kpThreadPool *p = kpThreadPool_create(-1);

    printf("Threadpool has %zu workers\n", kpThreadPool_getWorkers(p));

    kpThreadPool_pushTask(p, &my_task, (void *)10);

    kpThreadPool_destroy(p);
    return 0;
}