Skip to content

Tectu/cpp-threadpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published