#include <gtopt/work_pool.hpp>
template<typename Key = int64_t, typename KeyCompare = std::less<Key>>
BasicWorkPool class
Adaptive thread pool with generic priority key.
| Template parameters | |
|---|---|
| Key | Secondary sort-key type for task ordering within the same TaskPriority tier. Default is int64_t. |
| KeyCompare | Comparator applied to keys. Default std::less<Key> gives "smaller key → higher priority". Pass std::greater<Key> to obtain "larger key → higher
priority" (the original pre-refactor behavior). |
All methods are defined inline here so that any specialization can be instantiated without a separate translation unit.
Derived classes
- class AdaptiveWorkPool final
- Default work pool using
int64_tpriority key withstd::lesssemantics (smaller key → higher priority).
Public types
- class SlotReleaseGuard
- struct Statistics
- using key_compare = KeyCompare
- using key_type = Key
- using Requirements = BasicTaskRequirements<Key>
Constructors, destructors, conversion operators
- BasicWorkPool(BasicWorkPool&&) deleted
- BasicWorkPool(const BasicWorkPool&) deleted
- BasicWorkPool(WorkPoolConfig config = WorkPoolConfig {}) explicit
- ~BasicWorkPool() noexcept
Public functions
- auto format_statistics() const -> std::string noexcept
- auto get_statistics() const -> Statistics noexcept
- void log_statistics() const
- auto max_memory_percent() const -> double noexcept
- auto max_process_rss_mb() const -> double noexcept
- auto max_threads() const -> int noexcept
- auto max_threads_ceiling() const -> int noexcept
- auto operator=(const BasicWorkPool&&) -> BasicWorkPool& deleted
- auto operator=(const BasicWorkPool&) -> BasicWorkPool& deleted
- auto release_slot_while_blocking() -> SlotReleaseGuard noexcept
- void shutdown()
- void start()
-
template<typename Func, typename... Args>auto submit(Func&& func, const Requirements& req = Requirements(), Args && ... args) -> std::expected<std::future<std::invoke_result_t<Func, Args...>>, std::error_code>
-
template<typename Func>auto submit_batch(std::vector<std::pair<Func, Requirements>>& tasks) -> std::vector<std::expected<std::future<std::invoke_result_t<Func>>, std::error_code>>
-
template<typename Func>auto submit_lambda(Func&& func, Requirements req = {}) -> auto
Function documentation
template<typename Key, typename KeyCompare>
double gtopt:: BasicWorkPool<Key, KeyCompare>:: max_memory_percent() const noexcept
System-wide memory-usage backstop threshold (percent). Routine throttling is the marginal-RSS gate; this fires only near OOM.
template<typename Key, typename KeyCompare>
double gtopt:: BasicWorkPool<Key, KeyCompare>:: max_process_rss_mb() const noexcept
Process-RSS budget driving the marginal-RSS dispatch gate (0 = the gate + measured model are disabled). Exposed for tests / diagnostics.
template<typename Key, typename KeyCompare>
int gtopt:: BasicWorkPool<Key, KeyCompare>:: max_threads() const noexcept
Thread cap configured for this pool. Needed by tests that verify make_solver_work_pool(cpu_factor) clamps its thread count correctly (e.g. tiny cpu_factor must floor to 1 thread to give a genuine serial baseline). Safe to call from any thread — max_threads_ may grow at runtime up to the ceiling.
template<typename Key, typename KeyCompare>
int gtopt:: BasicWorkPool<Key, KeyCompare>:: max_threads_ceiling() const noexcept
Absolute growth ceiling for max_threads() (the un-clamped CPU budget). Equals max_threads() initially when growth is disabled.
template<typename Key, typename KeyCompare>
SlotReleaseGuard gtopt:: BasicWorkPool<Key, KeyCompare>:: release_slot_while_blocking() noexcept
Acquire a guard that releases this task's worker slot for the duration of an external blocking wait. See SlotReleaseGuard for rationale and usage.
template<typename Key, typename KeyCompare>
template<typename Func>
std::vector<std::expected<std::future<std::invoke_result_t<Func>>, std::error_code>> gtopt:: BasicWorkPool<Key, KeyCompare>:: submit_batch(std::vector<std::pair<Func, Requirements>>& tasks)
Submit multiple callables under a single lock acquisition. Returns a vector of futures, one per callable.