Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractEvent thread safety #295

Closed
arturoc opened this issue Sep 24, 2013 · 1 comment
Closed

AbstractEvent thread safety #295

arturoc opened this issue Sep 24, 2013 · 1 comment
Labels

Comments

@arturoc
Copy link
Contributor

arturoc commented Sep 24, 2013

in AbstractEvent::notify:

    void notify(const void* pSender, TArgs& args)
/// Sends a notification to all registered delegates. The order is
/// determined by the TStrategy. This method is blocking. While executing,
/// the list of delegates may be modified. These changes don't
/// influence the current active notifications but are activated with
/// the next notify. If a delegate is removed during a notify(), the
/// delegate will no longer be invoked (unless it has already been
/// invoked prior to removal). If one of the delegates throws an exception,
/// the notify method is immediately aborted and the exception is propagated
/// to the caller.
{
Poco::ScopedLockWithUnlock<TMutex> lock(_mutex);

    if (!_enabled) return;

    // thread-safeness:
    // copy should be faster and safer than blocking until
    // execution ends
    TStrategy strategy(_strategy);
    lock.unlock();
   strategy.notify(pSender, args);
}

The comment says:

If a delegate is removed during a notify(), the
delegate will no longer be invoked (unless it has already been
invoked prior to removal).

So if an object being destructed is being notified that will cause a segfault. Wouldn't it be better to just lock during the whole notification?

@aleks-f
Copy link
Member

aleks-f commented Oct 12, 2017

@arturoc it's been a while, but we're finally cleaning the backlog.

I'm not sure I understand the concern - how would locking the entire function scope prevent an object from being destroyed? And, which object is of concern - event, strategy, delegate?

/cc @obiltschnig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants