Ginger 1.1.5; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
thread_pool.hpp File Reference
#include <condition_variable>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <queue>
#include <thread>
#include <type_traits>
#include <utility>
Include dependency graph for thread_pool.hpp:

Go to the source code of this file.

Classes

class  ginger::thread_pool
 

Namespaces

namespace  ginger
 

Functions

auto ginger::get_thread_pool () -> thread_pool &
 Convenience accessor returning a singleton thread pool.
 

Detailed Description

Minimal header-only thread pool for C++17.

Owns a fixed set of worker threads that process tasks from a shared queue. Tasks are enqueued via enqueue() which returns a std::future to the result.

Usage:

auto future = pool.enqueue([] { return 42; });
int result = future.get();
Definition thread_pool.hpp:35
auto enqueue(F &&task) -> std::future< std::invoke_result_t< std::decay_t< F > > >
Definition thread_pool.hpp:76

The destructor waits for all pending tasks to finish and joins all worker threads. It is safe to destroy the pool while tasks are still running — remaining tasks are abandoned.