mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
CThreadPool: Fix a race when starting threads
There was a race where threads were themselves responsible for increasing the counter for the number of running threads. This left an open window where the thread was already started, but our counter was not yet increased. The effect of this race would be that we start more threads than we should. Fix this by increasing the counter before actually starting new worker threads. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
@@ -104,7 +104,7 @@ bool CThreadPool::threadNeeded() const {
|
||||
|
||||
void CThreadPool::threadFunc() {
|
||||
CMutexLocker guard(m_mutex);
|
||||
m_num_threads++;
|
||||
// m_num_threads was already increased
|
||||
m_num_idle++;
|
||||
|
||||
while (true) {
|
||||
@@ -152,6 +152,7 @@ void CThreadPool::addJob(CJob *job) {
|
||||
return;
|
||||
|
||||
// Start a new thread for our pool
|
||||
m_num_threads++;
|
||||
CThread::startThread(threadPoolFunc, this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user