C++ 20 Threadpool library.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jorijn van der Graaf f71cb43e85
fix(threadpool): batches run every task once, and Stop ends the whole pool
- Enqueue(vector) dropped tasks when the count didn't divide by the
  workers: the last one got only the remainder. Tasks are now split as
  evenly as the count allows, each worker's taskCount grows by what it
  was given (the single-task Enqueue picks by it), and Start(1), which
  has no workers, leaves the batch for the caller's JoinPool.
- Stop wakes every slot, JoinPool's too, after joining the workers: a
  thread that had joined the pool slept on. It takes each slot's mutex
  before notifying, so a waiter between its check and its sleep can't miss
  the wake-up, and works on the pool it started with. Again, or before
  Start, it does nothing; joining a thread twice threw. Its documentation
  says what it doesn't do: stop from a pool task, or from two threads at
  once, run tasks enqueued once it has begun, or have JoinPool wait for it.
- Tests: EnqueueBatch, StopJoinPool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 20:20:29 +02:00
implementations fix(threadpool): batches run every task once, and Stop ends the whole pool 2026-10-20 20:20:29 +02:00
interfaces fix(threadpool): batches run every task once, and Stop ends the whole pool 2026-10-20 20:20:29 +02:00
tests fix(threadpool): batches run every task once, and Stop ends the whole pool 2026-10-20 20:20:29 +02:00
.gitignore updated project 2025-05-07 19:10:22 +02:00
LICENSE initial commit 2025-02-17 22:31:53 +01:00
LICENSE.GPL license update 2026-07-22 17:58:06 +02:00
project.cpp fix(threadpool): batches run every task once, and Stop ends the whole pool 2026-10-20 20:20:29 +02:00
readme.md initial commit 2025-02-17 22:31:53 +01:00

About

This is a threadpool library for C++ 20

How to use

#include <print>

import Crafter.Thread;
using namespace Crafter::Thread;

int main() {
    ThreadPool::Start(3);
    ThreadPool::Enqueue({[](){std::println("1");}, [](){std::println("2");}, [](){std::println("3");}, [](){std::println("4");}, [](){std::println("5");},[](){std::println("6");}, [](){std::println("7");}, [](){std::println("8");}, [](){std::println("9");}, [](){std::println("10");}});
    ThreadPool::Stop();
}

When running this above code the prints will be spread across 2 threads. This can be seen in the main.cpp sample by running crafter-build -c test -r