threadman 0.1.0
Header-only C++23 managed threads, dynamic pools, futures, and executors
Loading...
Searching...
No Matches
Classes | Namespaces
future_wait_pool.hpp File Reference

threadman::FutureWaitPool — a dynamically-scaling executor specialized for blocking waits, primarily adopting std::future / std::shared_future into ThreadMan's Future<T>. More...

#include <threadman/config.hpp>
#include <threadman/executor.hpp>
#include <threadman/future.hpp>
#include <threadman/stats.hpp>
#include <threadman/thread_pool.hpp>
#include <commons/display_info.hpp>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <functional>
#include <future>
#include <memory>
#include <string>
#include <string_view>
#include <thread>
#include <type_traits>
#include <utility>
#include <vector>
Include dependency graph for future_wait_pool.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  threadman::FutureWaitPoolOptions
 Configuration for a FutureWaitPool. More...
 
class  threadman::FutureWaitPool
 Elastic executor for blocking future-waits. More...
 

Namespaces

namespace  threadman
 

Detailed Description

threadman::FutureWaitPool — a dynamically-scaling executor specialized for blocking waits, primarily adopting std::future / std::shared_future into ThreadMan's Future<T>.

A std::future offers no completion callback, so the only way to learn it is ready is to block a thread on get(). That makes a fixed-size pool a poor fit: a handful of slow futures can occupy every worker. FutureWaitPool wraps a ThreadPool tuned for exactly this — it keeps min_workers core threads and scales up to max_workers whenever waits back up (a worker blocked in get() counts as active, never idle, so saturation reliably triggers scale-up), then retires the overflow once the backlog clears.

Typical use:

auto wp = mgr.make_future_wait_pool({.min_workers = 1, .max_workers = 8});
threadman::Future<int> f = wp.add(some_std_future);
auto chained = f.then(cpu_pool, [](int v){ return v * 2; });
Definition future.hpp:239
auto then(Exec &exec, Fn &&fn)
Register a continuation; consumes this future.
Definition future.hpp:568

The returned value is a first-class threadman::Future<T>: it supports .get(), .then(), .on_error(), snapshots, and share() like any other.