From 7ea11f829251618ef0e881f809d29a2f696181ed Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 8 Feb 2022 14:50:57 +0000 Subject: [PATCH] Fix an issue with unchecked_map::~unchecked_map where the condition variable signal can be missed since the object mutex isn't acquired while setting stopped=true. Converts unchecked_map::stopped to a non-atomic bool since it needs a mutex anyway. (#3723) --- nano/node/unchecked_map.cpp | 4 +++- nano/node/unchecked_map.hpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nano/node/unchecked_map.cpp b/nano/node/unchecked_map.cpp index e73d4546..f36bcbbf 100644 --- a/nano/node/unchecked_map.cpp +++ b/nano/node/unchecked_map.cpp @@ -63,8 +63,10 @@ size_t nano::unchecked_map::count (nano::transaction const & transaction) const void nano::unchecked_map::stop () { - if (!stopped.exchange (true)) + nano::unique_lock lock{ mutex }; + if (!stopped) { + stopped = true; condition.notify_all (); // Notify flush (), run () } } diff --git a/nano/node/unchecked_map.hpp b/nano/node/unchecked_map.hpp index a6523498..76b882ee 100644 --- a/nano/node/unchecked_map.hpp +++ b/nano/node/unchecked_map.hpp @@ -56,7 +56,7 @@ private: std::deque> buffer; std::deque> back_buffer; bool writing_back_buffer{ false }; - std::atomic stopped{ false }; + bool stopped{ false }; nano::condition_variable condition; nano::mutex mutex; std::thread thread;