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(); }