From 28c8678ea21ed186d71f9fc82a18421845e457e3 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 4 Nov 2016 23:32:57 -0700 Subject: [PATCH] SafeThread: Use atomic for m_active. --- include/support/SafeThread.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/support/SafeThread.h b/include/support/SafeThread.h index 2cb9ba9031..a13d12af27 100644 --- a/include/support/SafeThread.h +++ b/include/support/SafeThread.h @@ -18,11 +18,12 @@ namespace wpi { // Base class for SafeThreadOwner threads. class SafeThread { public: + SafeThread() { m_active = true; } virtual ~SafeThread() = default; virtual void Main() = 0; std::mutex m_mutex; - bool m_active = true; + std::atomic_bool m_active; std::condition_variable m_cond; }; @@ -92,7 +93,6 @@ inline void SafeThreadOwnerBase::Start(SafeThread* thr) { inline void SafeThreadOwnerBase::Stop() { SafeThread* thr = m_thread.exchange(nullptr); if (!thr) return; - std::lock_guard lock(thr->m_mutex); thr->m_active = false; thr->m_cond.notify_one(); }