1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

MCOL-4486 Removing deadlock implicitly introduced by the deprecated class boost::condition

This commit is contained in:
Roman Nozdrin
2021-02-03 16:43:04 +00:00
parent d2cc656fdf
commit 6f9cc0a067
2 changed files with 15 additions and 17 deletions

View File

@ -87,14 +87,15 @@ void ThreadPool::setQueueSize(size_t queueSize)
void ThreadPool::pruneThread()
{
boost::mutex::scoped_lock lock2(fPruneMutex);
boost::unique_lock<boost::mutex> lock2(fPruneMutex);
while(true)
{
boost::system_time timeout = boost::get_system_time() + boost::posix_time::minutes(1);
if (fStop)
return;
if (!fPruneThreadEnd.timed_wait(fPruneMutex, timeout))
if (fPruneThreadEnd.wait_for(lock2, boost::chrono::minutes{1}) ==
boost::cv_status::timeout)
{
while(!fPruneThreads.empty())
{
@ -327,8 +328,7 @@ void ThreadPool::beginThread() throw()
utils::setThreadName("Idle");
try
{
boost::mutex::scoped_lock lock1(fMutex);
boost::system_time timeout = boost::get_system_time() + boost::posix_time::minutes(10);
boost::unique_lock<boost::mutex> lock1(fMutex);
for (;;)
{
@ -347,7 +347,8 @@ void ThreadPool::beginThread() throw()
else
{
// Wait no more than 10 minutes
if (!fNeedThread.timed_wait(lock1, timeout)) // false means it timed out
if (fNeedThread.wait_for(lock1, boost::chrono::minutes{10}) ==
boost::cv_status::timeout)
{
if (fThreadCount > fMaxThreads)
{
@ -356,8 +357,6 @@ void ThreadPool::beginThread() throw()
--fThreadCount;
return;
}
timeout = boost::get_system_time() + boost::posix_time::minutes(10);
}
}
}
@ -434,8 +433,6 @@ void ThreadPool::beginThread() throw()
ml.logWarningMessage( message );
}
}
timeout = boost::get_system_time() + boost::posix_time::minutes(10);
fThreadAvailable.notify_all();
}
}

View File

@ -39,10 +39,12 @@
#include <stdint.h>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/locks.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/chrono/chrono.hpp>
#include <memory>
@ -54,7 +56,6 @@
namespace threadpool
{
// Taken from boost::thread_group and adapted
class ThreadPoolGroup
{
@ -351,8 +352,8 @@ private:
uint32_t fIssued;
boost::mutex fMutex;
boost::condition fThreadAvailable; // triggered when a thread is available
boost::condition fNeedThread; // triggered when a thread is needed
boost::condition_variable fThreadAvailable; // triggered when a thread is available
boost::condition_variable fNeedThread; // triggered when a thread is needed
ThreadPoolGroup fThreads;
bool fStop;
@ -365,7 +366,7 @@ private:
bool fDebug;
boost::mutex fInitMutex;
boost::mutex fPruneMutex;
boost::condition fPruneThreadEnd;
boost::condition_variable fPruneThreadEnd;
boost::thread* fPruneThread;
std::stack<boost::thread::id> fPruneThreads; // A list of stale thread IDs to be joined
};