gtopt/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:

  1. TaskPriority enum (Critical > High > Medium > Low) – used as the primary tier and also controls the CPU load threshold for scheduling.
  2. A generic Key type with a configurable KeyCompare comparator – used as the secondary sort within the same TaskPriority tier.

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_t priority key with std::less semantics (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 KeyCompare = std::less<Key>>
class gtopt::BasicWorkPool
Adaptive thread pool with generic priority key.
struct gtopt::BasicWorkPool::Statistics
template<typename T T = void, typename Key = int64_t, typename KeyCompare KeyCompare = std::less<Key>>
class gtopt::Task
Generic task wrapper with type-erased key type.
struct gtopt::WorkPoolConfig