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:
parent
45017fbe3c
commit
6e6b4a1829
1 changed files with 5 additions and 2 deletions
|
|
@ -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...);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue