Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#pragma once
2
3// BSD 3-Clause License
4// Copyright (c) 2024, 🍀☀🌕🌥 🌊
5// See the LICENSE file in the project root for full license information.
6
15#include <cstddef>
16#include <chrono>
17
19
20 // Thread management configuration
21 constexpr size_t default_thread_count = 4;
22 constexpr size_t max_threads = 64;
23 constexpr size_t min_threads = 1;
24
25 // Queue configuration
26 constexpr size_t default_queue_size = 1024;
27 constexpr size_t unlimited_queue_size = 0;
28
29 // Timing configuration
30 constexpr auto default_wake_interval = std::chrono::milliseconds(100);
31 constexpr auto default_shutdown_timeout = std::chrono::seconds(5);
32 constexpr auto default_worker_idle_timeout = std::chrono::seconds(30);
33
34 // Performance configuration
35 constexpr bool default_yield_on_idle = true;
36
58#ifdef THREAD_WORK_STEALING_ENABLED
59 constexpr bool default_work_stealing = true;
60#else
61 constexpr bool default_work_stealing = false;
62#endif
63
64 // Work-stealing tuning parameters
65
69 constexpr size_t default_max_steal_attempts = 3;
70
74 constexpr auto default_steal_backoff = std::chrono::microseconds(50);
75
76 constexpr bool default_pin_threads = false;
77 constexpr bool default_use_priorities = false;
78
79 // Resource limits
80 constexpr size_t max_queue_size = 1024 * 1024; // 1M jobs max
81 constexpr size_t default_stack_size = 1024 * 1024; // 1MB stack
82
83 // Feature flags
84 constexpr bool enable_coroutines = __cplusplus >= 202002L;
85 constexpr bool enable_statistics = true;
86 constexpr bool enable_debugging = false;
87
88 // Thread naming
89 constexpr const char* default_thread_prefix = "worker";
90 constexpr const char* default_pool_name = "thread_pool";
91
95 static_assert(default_thread_count >= min_threads, "Thread count must be at least minimum");
96 static_assert(default_thread_count <= max_threads, "Thread count must not exceed maximum");
98 "Queue size must be positive or unlimited");
99 static_assert(max_queue_size > default_queue_size, "Max queue size must exceed default");
100
101} // namespace kcenon::thread::config
constexpr auto default_worker_idle_timeout
Definition config.h:32
constexpr bool default_work_stealing
Enable work stealing for improved load balancing.
Definition config.h:61
constexpr bool enable_debugging
Definition config.h:86
constexpr bool enable_coroutines
Definition config.h:84
constexpr bool default_pin_threads
Definition config.h:76
constexpr size_t default_queue_size
Definition config.h:26
constexpr auto default_wake_interval
Definition config.h:30
constexpr auto default_shutdown_timeout
Definition config.h:31
constexpr auto default_steal_backoff
Default backoff duration between steal attempts (microseconds).
Definition config.h:74
constexpr size_t unlimited_queue_size
Definition config.h:27
constexpr bool enable_statistics
Definition config.h:85
constexpr size_t max_threads
Definition config.h:22
constexpr size_t default_stack_size
Definition config.h:81
constexpr size_t default_max_steal_attempts
Default maximum steal attempts before backing off.
Definition config.h:69
constexpr size_t default_thread_count
Definition config.h:21
constexpr const char * default_thread_prefix
Definition config.h:89
constexpr bool default_yield_on_idle
Definition config.h:35
constexpr bool default_use_priorities
Definition config.h:77
constexpr size_t max_queue_size
Definition config.h:80
constexpr size_t min_threads
Definition config.h:23
constexpr const char * default_pool_name
Definition config.h:90