From 9897a49e1ad42c7a44205cc0c01813bd91c93f8c Mon Sep 17 00:00:00 2001 From: Meeh Date: Sat, 8 Feb 2014 03:15:08 +0100 Subject: [PATCH] Rewrite the thread stop in Queue --- Queue.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Queue.h b/Queue.h index 449ff806..316084a9 100644 --- a/Queue.h +++ b/Queue.h @@ -98,17 +98,18 @@ namespace util { public: - MsgQueue (): m_Thread (std::bind (&MsgQueue::Run, this)) {}; + MsgQueue (): m_Thread (std::bind (&MsgQueue::Run, this)) , running(1) {}; void Stop() { - m_Thread.detach(); + running = 0; + m_Thread.join(); } private: void Run () { Msg * msg = nullptr; - while ((msg = Queue::GetNext ()) != nullptr) + while ((msg = Queue::GetNext ()) != nullptr && running) { msg->Process (); delete msg; @@ -117,6 +118,7 @@ namespace util private: std::thread m_Thread; + int running; }; } }