| doc_id | THR-GUID-020 |
|---|---|
| doc_title | Thread System - Frequently Asked Questions |
| doc_version | 1.0.0 |
| doc_date | 2026-04-04 |
| doc_status | Released |
| project | thread_system |
| category | GUID |
SSOT: This document is the single source of truth for Thread System - Frequently Asked Questions.
Version: 0.1.0 Last Updated: 2025-11-11 Audience: Users, Developers
This FAQ addresses common questions about the thread_system, covering thread pools, job scheduling, synchronization, and performance.
A high-performance thread pool and job scheduling system for C++20:
- Thread pools with configurable size
- Job scheduling with priorities
- Work stealing for load balancing
- Future/Promise support
- Thread-safe by default
#include <thread/thread_pool.hpp>
auto pool = thread_pool::create(4); // 4 worker threads
auto future = pool->submit([]() {
return compute_result();
});
auto result = future.get();// Fixed size pool
auto pool = thread_pool::create(4);
// Auto-sized (hardware_concurrency)
auto pool = thread_pool::create();
// With configuration
auto pool = thread_pool::create({
.thread_count = 8,
.queue_size = 1000,
.enable_work_stealing = true
});// Fire-and-forget
pool->submit([]() {
do_work();
});
// With return value
auto future = pool->submit([]() {
return 42;
});
int result = future.get();
// With parameters
pool->submit([](int x, int y) {
return x + y;
}, 10, 20);// High priority job
pool->submit([]() {
critical_work();
}, priority::high);
// Normal priority (default)
pool->submit([]() {
normal_work();
});
// Low priority
pool->submit([]() {
background_work();
}, priority::low);Benchmarks (4-core CPU):
- Job submission: <100 ns
- Context switch: ~1 μs
- Throughput: 1M jobs/s
Yes, all operations are thread-safe.
// Multiple threads can submit concurrently
std::vector<std::thread> threads;
for (int i = 0; i < 10; ++i) {
threads.emplace_back([&pool]() {
pool->submit([]() { /* work */ });
});
}// Wait for specific job
auto future = pool->submit([]() { return 42; });
int result = future.wait();
// Wait for all jobs
pool->wait_for_all();
// Wait with timeout
if (pool->wait_for(std::chrono::seconds(5))) {
// Completed
} else {
// Timeout
}// Graceful shutdown (finish pending jobs)
pool->shutdown();
pool->wait_for_all();
// Immediate shutdown
pool->shutdown_now();// Automatic metrics
auto pool = thread_pool::create(4, {
.enable_monitoring = true
});
// Metrics available:
// - thread_pool_active_threads
// - thread_pool_queued_tasks
// - thread_pool_completed_tasksDocumentation:
Support:
Last Updated: 2025-11-11