From 6e6b4a1829577acebe3fc07861a954f296e729c1 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Fri, 26 Aug 2022 18:37:36 +0100 Subject: [PATCH] observer_set: do not call the observer callbacks holding the lock (#3922) It unnecessarily leaves the door open for deadlocks. --- nano/lib/utility.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nano/lib/utility.hpp b/nano/lib/utility.hpp index b547e5324..34167a2cb 100644 --- a/nano/lib/utility.hpp +++ b/nano/lib/utility.hpp @@ -158,8 +158,11 @@ public: } void notify (T... args) { - nano::lock_guard lock (mutex); - for (auto & i : observers) + nano::unique_lock lock (mutex); + auto observers_copy = observers; + lock.unlock (); + + for (auto & i : observers_copy) { i (args...); }