Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::worker_policy Struct Reference

Worker behavior policy configuration. More...

#include <worker_policy.h>

Collaboration diagram for kcenon::thread::worker_policy:
Collaboration graph

Static Public Member Functions

static worker_policy default_policy ()
 Create a default worker policy.
 
static worker_policy high_performance ()
 Create a high-performance worker policy.
 
static worker_policy low_latency ()
 Create a low-latency worker policy.
 
static worker_policy power_efficient ()
 Create a power-efficient worker policy.
 

Public Attributes

scheduling_policy scheduling = scheduling_policy::fifo
 
std::chrono::milliseconds idle_timeout = config::default_worker_idle_timeout
 
bool yield_on_idle = config::default_yield_on_idle
 
bool sleep_when_idle = true
 
std::chrono::microseconds idle_sleep_duration {100}
 
bool enable_work_stealing = config::default_work_stealing
 
steal_policy victim_selection = steal_policy::random
 
size_t max_steal_attempts = 3
 
std::chrono::microseconds steal_backoff {50}
 
bool pin_to_cpu = config::default_pin_threads
 
int preferred_cpu = -1
 
size_t max_jobs_per_batch = 10
 
bool continue_on_exception = true
 
size_t max_consecutive_failures = 5
 
bool enable_statistics = config::enable_statistics
 
std::string worker_name_prefix = config::default_thread_prefix
 

Detailed Description

Worker behavior policy configuration.

This structure defines how a worker thread should behave in various situations and under different load conditions.

Definition at line 62 of file worker_policy.h.

Member Function Documentation

◆ default_policy()

static worker_policy kcenon::thread::worker_policy::default_policy ( )
inlinestatic

Create a default worker policy.

Definition at line 94 of file worker_policy.h.

94 {
95 return worker_policy{};
96 }

◆ high_performance()

static worker_policy kcenon::thread::worker_policy::high_performance ( )
inlinestatic

Create a high-performance worker policy.

Definition at line 101 of file worker_policy.h.

101 {
102 worker_policy policy;
103 policy.yield_on_idle = false;
104 policy.sleep_when_idle = false;
105 policy.enable_work_stealing = true;
106 policy.max_jobs_per_batch = 20;
107 return policy;
108 }

References enable_work_stealing, max_jobs_per_batch, sleep_when_idle, and yield_on_idle.

◆ low_latency()

static worker_policy kcenon::thread::worker_policy::low_latency ( )
inlinestatic

Create a low-latency worker policy.

Definition at line 113 of file worker_policy.h.

113 {
114 worker_policy policy;
115 policy.scheduling = scheduling_policy::priority;
116 policy.yield_on_idle = false;
117 policy.idle_sleep_duration = std::chrono::microseconds{10};
118 policy.max_jobs_per_batch = 1;
119 return policy;
120 }
@ priority
Priority-based scheduling.

References idle_sleep_duration, max_jobs_per_batch, kcenon::thread::priority, scheduling, and yield_on_idle.

◆ power_efficient()

static worker_policy kcenon::thread::worker_policy::power_efficient ( )
inlinestatic

Create a power-efficient worker policy.

Definition at line 125 of file worker_policy.h.

125 {
126 worker_policy policy;
127 policy.yield_on_idle = true;
128 policy.sleep_when_idle = true;
129 policy.idle_sleep_duration = std::chrono::milliseconds{1};
130 policy.enable_work_stealing = false;
131 return policy;
132 }

References enable_work_stealing, idle_sleep_duration, sleep_when_idle, and yield_on_idle.

Member Data Documentation

◆ continue_on_exception

bool kcenon::thread::worker_policy::continue_on_exception = true

Definition at line 84 of file worker_policy.h.

◆ enable_statistics

bool kcenon::thread::worker_policy::enable_statistics = config::enable_statistics

Definition at line 88 of file worker_policy.h.

◆ enable_work_stealing

◆ idle_sleep_duration

std::chrono::microseconds kcenon::thread::worker_policy::idle_sleep_duration {100}

Definition at line 70 of file worker_policy.h.

70{100};

Referenced by low_latency(), and power_efficient().

◆ idle_timeout

std::chrono::milliseconds kcenon::thread::worker_policy::idle_timeout = config::default_worker_idle_timeout

Definition at line 67 of file worker_policy.h.

◆ max_consecutive_failures

size_t kcenon::thread::worker_policy::max_consecutive_failures = 5

Definition at line 85 of file worker_policy.h.

◆ max_jobs_per_batch

size_t kcenon::thread::worker_policy::max_jobs_per_batch = 10

Definition at line 81 of file worker_policy.h.

Referenced by high_performance(), and low_latency().

◆ max_steal_attempts

◆ pin_to_cpu

bool kcenon::thread::worker_policy::pin_to_cpu = config::default_pin_threads

Definition at line 79 of file worker_policy.h.

◆ preferred_cpu

int kcenon::thread::worker_policy::preferred_cpu = -1

Definition at line 80 of file worker_policy.h.

◆ scheduling

scheduling_policy kcenon::thread::worker_policy::scheduling = scheduling_policy::fifo

Definition at line 64 of file worker_policy.h.

Referenced by low_latency().

◆ sleep_when_idle

bool kcenon::thread::worker_policy::sleep_when_idle = true

Definition at line 69 of file worker_policy.h.

Referenced by high_performance(), and power_efficient().

◆ steal_backoff

std::chrono::microseconds kcenon::thread::worker_policy::steal_backoff {50}

◆ victim_selection

◆ worker_name_prefix

std::string kcenon::thread::worker_policy::worker_name_prefix = config::default_thread_prefix

Definition at line 89 of file worker_policy.h.

◆ yield_on_idle

bool kcenon::thread::worker_policy::yield_on_idle = config::default_yield_on_idle

Definition at line 68 of file worker_policy.h.

Referenced by high_performance(), low_latency(), and power_efficient().


The documentation for this struct was generated from the following file: