GitHunt
TE

Tectu/cpp-threadpool

A simple to use, robust and flexible C++20 thread pool.

standard license

Overview

A simple to use, robust and flexible thread pool written in C++20.

Features:

  • Written in modern C++20
  • Header-only
  • Granular locking to improve mixed read/write loads
  • High-level status interface
  • Generic enqueuing interface allow any callable, not just functions

Usage

Basic usage looks like this:

// Initialize threadpool with four workers (threads)
jbo::thread_pool tp(4);

// Enqueue long running tasks
std::vector<std::future<int>> results;
for (std::size_t i = 0; i < 10; i++) {

    // Enqueue using lambda
    auto result = tp.enqueue([i]() -> int {
        std::this_thread::sleep_for(std::chrono::seconds(1));
        return i * i;
    });

    results.emplace_back(std::move(result));
}

// Collect results
for (auto& result : results)
    std::cout << "result: "  << result.get() << std::endl;

Languages

C++91.9%CMake8.1%

Contributors

BSD 2-Clause "Simplified" License
Created October 11, 2022
Updated July 26, 2025
Tectu/cpp-threadpool | GitHunt