I have a Boost.Signals2 signal on object 1, and I connect to it on object 2.
If object 2 is destructed the signal will not disconnect which can lead to bad things when its signaled.
To resolve this I keep a scoped_connection
on object 2. The problem now is what if object 1 destructs with the signal and then object 2 destructs.
Will it cause problems? Is there any better way to resolve the general issue? (have a connection from object 1 -> object 2 that will disconnect when on of them destructs).
A code that demonstrates the issue:
auto sig = new signal<void ()>();
auto conn = new scoped_connection(sig.connect(&some_function));
delete sig;
delete conn;
Is this safe?
Check
Especially the part:
"However, with Boost.Signals2 one may track any object which is managed by a shared_ptr, by using slot::track. A slot will automatically disconnect when any of its tracked objects expire. In addition, Boost.Signals2 will ensure that no tracked object expires while the slot it is associated with is in mid-execution. It does so by creating temporary shared_ptr copies of the slot's tracked objects before executing it. "
Does this solve your issue?