A header only thread pool targeting C++20
Clone the repo
git clone [email protected]:haciMMicah/pool_party.git && cd pool_party
Build the tests
mkdir build && cd build && cmake ../ && cmake --build .
Run the tests
./pool_party_tests
./pool_party_tests_performance_tests
// Create a thread pool with std::thread::hardware_concurrency() number of threads
pool_party::thread_pool pool{};
// Create a thread pool with a given number of threads
pool_party::thread_pool pool{8};
pool_party::thread_pool pool{};
pool.start();
pool.stop();
pool.num_threads();
pool.is_running();
pool_party::thread_pool pool{};
pool.start();
// Submit a detached job
pool.submit_detached([]{
std::cout << "Hello, World!\n";
})
// Submit a waitable job via futures
auto future = pool.submit([]{
std::cout << "Hello, World!\n";
})
future.wait();
// Submit a job with a callback to signal its completion
pool.submit_with_callback(
[]{ std::cout << "Hello, "; },
[](std::exception_ptr) noexcept { std::cout << "World!\n"; });
// Submit a job that passes its return value to a callback
pool.submit_with_callback(
[]{ std::cout << "Hello, "; return 42; },
[](std::exception_ptr, int num) noexcept { std::cout << "World! " << num << "\n"; });
// Submit a job that takes arguments that passes its return value to a callback
pool.submit_with_callback(
[](int num_to_return){ std::cout << "Hello, "; return num_to_return; },
[](std::exception_ptr, int num) noexcept { std::cout << "World! " << num << "\n"; },
42);