diff --git a/base/thread_pool_delayed.cpp b/base/thread_pool_delayed.cpp index 4f74a4b265..2e5676533c 100644 --- a/base/thread_pool_delayed.cpp +++ b/base/thread_pool_delayed.cpp @@ -156,6 +156,12 @@ void ThreadPool::ShutdownAndJoin() } m_threads.clear(); } + +bool ThreadPool::IsShoutedDown() +{ + lock_guard lk(m_mu); + return m_shutdown; +} } // namespace delayed } // namespace thread_pool } // namespace base diff --git a/base/thread_pool_delayed.hpp b/base/thread_pool_delayed.hpp index 45a64c4a7e..5179f4c811 100644 --- a/base/thread_pool_delayed.hpp +++ b/base/thread_pool_delayed.hpp @@ -69,6 +69,7 @@ public: // Sends a signal to the thread to shut down and waits for completion. void ShutdownAndJoin(); + bool IsShoutedDown(); static TimePoint Now() { return Clock::now(); } diff --git a/platform/platform.cpp b/platform/platform.cpp index fee0dff8d9..0132525c2e 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -329,21 +329,23 @@ unsigned Platform::CpuCores() const void Platform::ShutdownThreads() { ASSERT(m_networkThread && m_fileThread && m_backgroundThread, ()); + ASSERT(!m_networkThread->IsShoutedDown(), ()); + ASSERT(!m_fileThread->IsShoutedDown(), ()); + ASSERT(!m_backgroundThread->IsShoutedDown(), ()); m_batteryTracker.UnsubscribeAll(); m_networkThread->ShutdownAndJoin(); m_fileThread->ShutdownAndJoin(); m_backgroundThread->ShutdownAndJoin(); - - m_networkThread.reset(); - m_fileThread.reset(); - m_backgroundThread.reset(); } void Platform::RunThreads() { - ASSERT(!m_networkThread && !m_fileThread && !m_backgroundThread, ()); + ASSERT(!m_networkThread || (m_networkThread && m_networkThread->IsShoutedDown()), ()); + ASSERT(!m_fileThread || (m_fileThread && m_fileThread->IsShoutedDown()), ()); + ASSERT(!m_backgroundThread || (m_backgroundThread && m_backgroundThread->IsShoutedDown()), ()); + m_networkThread = make_unique(); m_fileThread = make_unique(); m_backgroundThread = make_unique();