mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-01 05:02:29 +07:00
Let dynamic threads wait for work instead of exiting immediately
Previously, dynamic threads exited as soon as their current task completed and the queue was empty. This caused excessive thread creation/destruction under bursty or long-lived workloads (e.g., SSE streaming), degrading tail latency. Now dynamic threads loop back and wait for CPPHTTPLIB_THREAD_POOL_IDLE_TIMEOUT (3s) before exiting, allowing them to be reused for subsequent tasks. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
09d00c099c
commit
ee5d15c842
@@ -10136,15 +10136,6 @@ inline void ThreadPool::worker(bool is_dynamic) {
|
||||
|
||||
assert(true == static_cast<bool>(fn));
|
||||
fn();
|
||||
|
||||
// Dynamic thread: exit if queue is empty after task completion
|
||||
if (is_dynamic) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (jobs_.empty()) {
|
||||
move_to_finished(std::this_thread::get_id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(CPPHTTPLIB_OPENSSL_SUPPORT) && !defined(OPENSSL_IS_BORINGSSL) && \
|
||||
|
||||
Reference in New Issue
Block a user