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

Corrade::Interconnect and thread-safety #59

Closed
foodchaining opened this issue Feb 27, 2019 · 2 comments
Closed

Corrade::Interconnect and thread-safety #59

foodchaining opened this issue Feb 27, 2019 · 2 comments

Comments

@foodchaining
Copy link

An excerpt from Boost.Signals2 docs (Automatic Connection Management):

Unfortunately, the boost::signals::trackable scheme cannot be made thread safe due to destructor ordering. The destructor of an class derived from boost::signals::trackable will always be called before the destructor of the base boost::signals::trackable class. However, for thread-safety the connection between the signal and object needs to be disconnected before the object runs its destructors. Otherwise, if an object being destroyed in one thread is connected to a signal concurrently invoking in another thread, the signal may call into a partially destroyed object.

What about Corrade::Interconnect? How thread-safe is it?

@mosra
Copy link
Owner

mosra commented Feb 27, 2019

This library is by design not doing any locking or other measures for thread safety, as that slows down single-threaded cases. The user is expected to handle this on the application side when needed, i.e. when touching shared data in signals/slots.

A different question is thread safety of slot execution. Qt's signal/slot implementation, for example, has a per-thread signal queue, meaning that a signal fired from one thread causes a slot to be executed in a thread belonging to slot's object (and not to signal's object). In my opinion such approach solves data races much better compared to extensive locking around or inside every signal/slot execution. It however makes the library implementation vastly more complicated and thus is not done here -- the target use case here is connecting arbitrary method calls within a single thread, suitable for example for UI code.

If you need guaranteed thread safety or advanced capabilities beyond the scope of this library, simply use either Qt's signal/slots or the one from boost. That's a completely valid (and encouraged) thing to do ;)

@mosra mosra added this to the 2019.0b milestone Jun 17, 2019
@mosra mosra added this to TODO in Interconnect via automation Jun 17, 2019
@mosra
Copy link
Owner

mosra commented Jun 17, 2019

Closing due to lack of activity.

@mosra mosra closed this as completed Jun 17, 2019
Interconnect automation moved this from TODO to Done Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Interconnect
  
Done
Development

No branches or pull requests

2 participants