diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index c7f8954d..0fa55b89 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -12,7 +12,6 @@ // creates the thread on construction. // stops and joins the thread on destruction. -#include #include #include #include @@ -55,16 +54,20 @@ public: // stop the back thread and join it ~periodic_worker() { - if (active_) + if (!active_) { - active_ = false; - cv_.notify_one(); - flusher_thread_.join(); + return; } + { + std::lock_guard lock(mutex_); + active_ = false; + } + cv_.notify_one(); + flusher_thread_.join(); } private: - std::atomic active_; + bool active_; std::thread flusher_thread_; std::mutex mutex_; std::condition_variable cv_;