From: Gunnar Beutner Date: Wed, 28 May 2014 13:57:48 +0000 (+0200) Subject: Fix a situation where some threadpool work items are never executed. X-Git-Tag: v2.0.0-beta2~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=157de9f3bbb23ed0439f85d9f99c86a90472de01;p=icinga2 Fix a situation where some threadpool work items are never executed. Fixes #6349 --- diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 6a7bf9fa2..365fe1fc9 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -272,8 +272,9 @@ void ThreadPool::ManagerThreadProc(void) int tthreads = wthreads - alive; /* Make sure there is at least one thread per CPU */ - if (alive + tthreads < std::max(boost::thread::hardware_concurrency(), 4U)) - tthreads = 1 - alive; + int ncput = std::max(boost::thread::hardware_concurrency() / QUEUECOUNT, 1U); + if (alive + tthreads < ncput) + tthreads = ncput - alive; /* Don't kill more than 8 threads at once. */ if (tthreads < -8) diff --git a/lib/base/threadpool.hpp b/lib/base/threadpool.hpp index 27d9e53d3..518d7a14b 100644 --- a/lib/base/threadpool.hpp +++ b/lib/base/threadpool.hpp @@ -30,6 +30,8 @@ namespace icinga { +#define QUEUECOUNT 4 + /** * A thread pool. * @@ -118,7 +120,7 @@ private: boost::condition_variable m_MgmtCV; bool m_Stopped; - Queue m_Queues[4]; + Queue m_Queues[QUEUECOUNT]; void ManagerThreadProc(void); };