mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
Spawn a dynamic thread when queued jobs outnumber idle threads
ThreadPool::enqueue only spawned a dynamic thread when no thread was idle. Threads already notified for an earlier job still counted as idle until they took it, so a burst of connections could leave jobs queued with no thread while the pool was below max_threads. With keep-alive, such a connection waited until another connection closed. Fix #2633
This commit is contained in:
1 parent
062666f3a1
commit
e97165b5dc
2 files changed
+35
-2
No files matched your search
@@ -12423,8 +12423,8 @@ inline bool ThreadPool::enqueue(std::function<void()> fn) {
|
||||
}
|
||||
jobs_.push_back(std::move(fn));
|
||||
|
||||
// Spawn a dynamic thread if no idle threads and under max
|
||||
if (idle_thread_count_ == 0 &&
|
||||
// Spawn a dynamic thread if jobs outnumber idle threads and under max
|
||||
if (jobs_.size() > idle_thread_count_ &&
|
||||
threads_.size() + dynamic_threads_.size() < max_thread_count_) {
|
||||
cleanup_finished_threads();
|
||||
dynamic_threads_.emplace_back(std::thread([this]() { worker(true); }));
|
||||
|
||||
Reference in new issue
Block a user