Global Namespaces
namespace qi
Classes (namespace qi)
class qi::Trackable
Functions (class qi::Trackable)
Functions (namespace qi)
class MyClass {
void callback();
};
qi::Signal<void> signal;
MyClass* my = new MyClass();
signal.connect(&MyClass::callback, my);
delete my;
signal(); // CRASH
In this code, the program will probably crash because the callback will be
called even though my
has been destroyed.
In this case, you need to use qi::Trackable
with qi::bind
so that the
callback won’t be called when your object dies. Note that you usually don’t
need to call qi::bind
explicitly, qi::Future::connect
and
qi::Signal::connect
do it for you.
MyClass should inherit from qi::Trackable
.
Then you must call destroy()
at the beginning of your destructor.
destroy()
ensures that all callbacks are finished before you start destructing your object.
You must not use boost::bind
if you want your object to be tracked!
#include <qi/trackable.hpp>
class MyClass : qi::Trackable<MyClass> {
~MyClass() {
destroy();
}
void callback();
};
qi::Signal<void> signal;
MyClass* my = new MyClass();
signal.connect(&MyClass::callback, my);
delete my;
signal(); // callback won't be called, no crash
Object tracking by blocking destruction while shared pointers are present. More...
#include <qi/trackable.hpp>
qi::TrackableBase
Trackable
()
()~Trackable
()weakPtr
()wait
()Inherit from Trackable to allow a form of tracking that blocks destruction while shared pointers are held. This allows using your class without a shared_ptr wrapper.
when inheriting from this class, you must invoke the destroy() method from your destructor, before any operation that puts your object in an invalid state.since destroy() blocks until all shared pointers are destroyed, deadlocks may occur if used improperly.
qi::Trackable<T>::
Trackable
()¶Default constructor.
()
qi::Trackable<T>::
~Trackable
()¶qi::Trackable<T>::
weakPtr
()¶Brief:
Returns: | A weak_ptr from this. While a shared_ptr exists from this weak_ptr, a call to destroy will block() |
---|
qi::Trackable<T>::
wait
()¶Blocks until destroy() is called and all shared_ptr built from weak_ptr() are deleted.
qi::
bind
(const AF& fun, ...)¶Bind a set of arguments or placeholders to a function.
Handles first function argument of kind boost::weak_ptr and qi::Trackable: will try to lock and throw qi::PointerLockException in case of failure