|
C++ Concurrency Sandbox
|
A priority-based thread pool that implements an Aging Algorithm. More...
Public Member Functions | |
| AgingPriorityPool (size_t threads) | |
| Constructs the pool and starts both workers and the aging monitor. | |
| void | enqueue (int priority, std::string name, std::function< void()> f) |
| Enqueues a task with an initial priority. | |
| ~AgingPriorityPool () | |
| Gracefully shuts down the monitor and worker threads. | |
A priority-based thread pool that implements an Aging Algorithm.
std::vector as a binary heap and a dedicated monitor thread to "age" tasks, ensuring that low-priority tasks eventually gain enough priority to be executed even under high load. Definition at line 50 of file AgingPriority.cpp.
|
inline |
Constructs the pool and starts both workers and the aging monitor.
| threads | Number of worker threads to spawn. |
Definition at line 131 of file AgingPriority.cpp.
|
inline |
Gracefully shuts down the monitor and worker threads.
Definition at line 163 of file AgingPriority.cpp.
|
inline |
Enqueues a task with an initial priority.
| priority | Initial importance level. |
| name | Name for identifying the task in logs. |
| f | The function to execute. |
Definition at line 144 of file AgingPriority.cpp.
References AgedTask::arrival_time, AgedTask::current_priority, AgedTask::func, AgedTask::original_priority, and AgedTask::task_name.
Referenced by main().