From 34acd9d47caa02c20b3b380db9aa1549673e576f 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. --- wpiutil/include/support/SafeThread.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpiutil/include/support/SafeThread.h b/wpiutil/include/support/SafeThread.h index 2cb9ba9..a13d12a 100644 --- a/wpiutil/include/support/SafeThread.h +++ b/wpiutil/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(); }