Fix potential deadlocks when building proxies/registering stubs in callbacks from events #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Observer design pattern has now been applied in a way that avoids deadlocks, has better support for concurrency, and provides more natural semantics for the client code:
An internal mutex is no longer locked while calling back the notify functors (the
listeners) registered by the user.
The non-interference/concurrency relationship between the notification functions
and the subscribe/unsubscribe functions has remained valid.
A new notification iteration can now begin in parallel (e.g.: on another thread)
with an on-going notification. The notification iterations do not interfere with
each other.
The functor callbacks registered by the user with calls to the subscribe function
are now deleted by the call to the unsubscribe function (i.e. deterministically from
the user's point of view), as opposed to being deleted at some point in the future
when/if a notification happens to be broadcast again (i.e. nondeterministically
from the user's point of view).
Internally, the implementation of the Event class template has been simplified
(e.g.: by only using one mutex and by letting go of the subscribe/unsubscribe
lists) and the code is now easier to understand.
Also, an object (of type std::lock_guard) is now used instead of explicit calls to the mutex lock and unlock functions (according to the RAII idiom), resulting in improved safety.