work_pool.hpp file
Adaptive thread pool with CPU monitoring and priority scheduling.
This module implements an adaptive work pool that:
- Dynamically adjusts task scheduling based on CPU load
- Supports task priorities (Low, Medium, High, Critical)
- Supports a generalized template priority key with configurable comparison
- Provides detailed statistics and monitoring
- Exception-safe design with proper cleanup
Priority Key Semantics
Tasks are ordered by a two-level key:
TaskPriorityenum (Critical > High > Medium > Low) – used as the primary tier and also controls the CPU load threshold for scheduling.- A generic
Keytype with a configurableKeyComparecomparator – used as the secondary sort within the sameTaskPrioritytier.
Default semantics (KeyCompare = std::less<Key>): if key1 < key2 then key1 has higher execution priority (is dequeued first). To obtain the reverse ordering (larger key = higher priority), instantiate the pool with KeyCompare = std::greater<Key>.
Namespaces
- namespace gtopt
- namespace gtopt::detail
Classes
- struct gtopt::ActiveTask
- class gtopt::AdaptiveWorkPool
- Default work pool using
int64_tpriority key withstd::lesssemantics (smaller key → higher priority). -
template<typename Key = int64_t>struct gtopt::BasicTaskRequirements
- Task requirements with a generic priority key.
-
template<typename Key = int64_t, typename KeyCompare = std::less<Key>>class gtopt::BasicWorkPool
- Adaptive thread pool with generic priority key.
- struct gtopt::MemoryClamp
- class gtopt::BasicWorkPool::SlotReleaseGuard
- struct gtopt::BasicWorkPool::Statistics
- class gtopt::SwapGrowthGate
-
template<typename T = void, typename Key = int64_t, typename KeyCompare = std::less<Key>>class gtopt::Task
- Queued unit of work: a type-erased callable plus its scheduling requirements.
- struct gtopt::TaskResourceStats
- Per-task resource usage sampled before/after execution.
- struct gtopt::WorkPoolConfig