observer_set: do not call the observer callbacks holding the lock (#3922)

It unnecessarily leaves the door open for deadlocks.
This commit is contained in:
Dimitrios Siganos 2022-08-26 18:37:36 +01:00 committed by GitHub
commit 6e6b4a1829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -158,8 +158,11 @@ public:
}
void notify (T... args)
{
nano::lock_guard<nano::mutex> lock (mutex);
for (auto & i : observers)
nano::unique_lock<nano::mutex> lock (mutex);
auto observers_copy = observers;
lock.unlock ();
for (auto & i : observers_copy)
{
i (args...);
}