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
Classes
- struct gtopt::ActiveTask
- class gtopt::AdaptiveWorkPool
- Default work pool using
int64_tpriority key withstd::lesssemantics (smaller key → higher priority). - struct gtopt::BasicTaskRequirements
- Task requirements with a generic priority key.
- class gtopt::BasicWorkPool
- Adaptive thread pool with generic priority key.
- struct gtopt::BasicWorkPool::Statistics
-
template<typename T T = void, typename Key = int64_class gtopt::Task
t, typename KeyCompare KeyCompare = std::less<Key>> - Generic task wrapper with type-erased key type.
- struct gtopt::WorkPoolConfig