]> granicus.if.org Git - icinga2/commitdiff
Fix a situation where some threadpool work items are never executed.
authorGunnar Beutner <gunnar@beutner.name>
Wed, 28 May 2014 13:57:48 +0000 (15:57 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 28 May 2014 13:57:48 +0000 (15:57 +0200)
Fixes #6349

lib/base/threadpool.cpp
lib/base/threadpool.hpp

index 6a7bf9fa2333bc4f39206ee42a9e39f257d2bb92..365fe1fc9a02eb6fa7dc815b512bf501831e54bd 100644 (file)
@@ -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)
index 27d9e53d30cd2232b1f9144cde9b36f2f1b92a9f..518d7a14b2dbf5ae1e5c37f0faca9d7a2badf891 100644 (file)
@@ -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);
 };