Skip to content

Commit f989bbd

Browse files
committed
Make sure that WQ threads are started after Daemonize().
Fixes #6063
1 parent b119c32 commit f989bbd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/base/workqueue.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ WorkQueue::WorkQueue(size_t maxItems)
3333
: m_ID(m_NextID++), m_MaxItems(maxItems), m_Stopped(false),
3434
m_Processing(false), m_ExceptionCallback(WorkQueue::DefaultExceptionCallback)
3535
{
36-
m_Thread = boost::thread(boost::bind(&WorkQueue::WorkerThreadProc, this));
37-
3836
m_StatusTimer = make_shared<Timer>();
3937
m_StatusTimer->SetInterval(10);
4038
m_StatusTimer->OnTimerExpired.connect(boost::bind(&WorkQueue::StatusTimerHandler, this));
@@ -68,6 +66,9 @@ void WorkQueue::Enqueue(const WorkCallback& callback, bool allowInterleaved)
6866

6967
boost::mutex::scoped_lock lock(m_Mutex);
7068

69+
if (m_Thread.get_id() == boost::thread::id())
70+
m_Thread = boost::thread(boost::bind(&WorkQueue::WorkerThreadProc, this));
71+
7172
if (!wq_thread) {
7273
while (m_Items.size() >= m_MaxItems)
7374
m_CVFull.wait(lock);
@@ -91,7 +92,8 @@ void WorkQueue::Join(bool stop)
9192
m_CVEmpty.notify_all();
9293
lock.unlock();
9394

94-
m_Thread.join();
95+
if (m_Thread.joinable())
96+
m_Thread.join();
9597
}
9698
}
9799

0 commit comments

Comments
 (0)