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)

This commit is contained in:
clemahieu 2022-02-08 14:50:57 +00:00 committed by GitHub
commit 7ea11f8292
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -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<nano::mutex> lock{ mutex };
if (!stopped)
{
stopped = true;
condition.notify_all (); // Notify flush (), run ()
}
}

View file

@ -56,7 +56,7 @@ private:
std::deque<boost::variant<insert, query>> buffer;
std::deque<boost::variant<insert, query>> back_buffer;
bool writing_back_buffer{ false };
std::atomic<bool> stopped{ false };
bool stopped{ false };
nano::condition_variable condition;
nano::mutex mutex;
std::thread thread;