I see. I think I will look more into weak_ptr/track() methods to achieve what I want because I might land up having shared_ptr< A > being a composition inside B and then in event of no further interaction with A's signal they would both exist for the lifetime of the program.

I'd posted a query here too: http://stackoverflow.com/questions/19476578/mixing-boostasio-and-boostsignals2-giving-problems

In the hack there I have assumed that signals make a copy of slots before executing them and hence that hack would work -> it would delete the actual functor when connecting dummy() and then the copy once slot() returns (assuming that the signal had been fired and the control was inside slot() when stop() was called). Is that assumption correct (about copying the list of slots before executing them) ? I got it from: http://stackoverflow.com/a/4490785/1060004



On Sun, Oct 20, 2013 at 8:22 PM, Frank Mori Hess-3 [via Boost] <[hidden email]> wrote:



On Sun, Oct 20, 2013 at 3:37 AM, ustulation <[hidden email]> wrote:
class A
{
/* has signals2::signal(s) for callbacks, fired when completion-handler of
various async operations are invoked (eg., async_read_until etc) */
};

class B
{
void registerListenersWith_A()
{
        /* has member-function listeners submitted to signals of class A eg., auto
self = shared_from_this();
shared_ptr_A->someSig_A.connect([self]{self->mem_func_B();}); */
}
void disconnectListenersWith_A()
{
        /* disconnect all boost::signals2::connection(s) made above */
}
};

auto shared_ptr_A = std::make_shared< A >();
{
auto shared_ptr_B = std::make_shared< B >();
give shared_ptr_B a copy of shared_ptr_A for use above.
shared_ptr_B->registerListenersWith_A();
//....some operations here.....
shared_ptr_B->disconnectListenersWith_A();
} //i want pointer managed by shared_ptr_B to be destroyed here in a
thread-safe manner (ie., no pending calls remain from A to B etc.


I'd think about using weak_ptr to break your cyclic shared_ptr object ownership between class A and B.  Also, you can use the track() method on slots to auto-disconnect the member function of class B when it's last owning shared_ptr expires, rather than binding a shared_ptr into the slot.  track() will also prevent the class B object from being destroyed mid-invocation by creating a temporary shared_ptr.

That said, as long as you manually call disconnect at some point, the disconnected slots in the signal will eventually be destroyed during cleanup, either in a later signal::connect call, a later signal invocation, or on signal destruction.


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


If you reply to this email, your message will be added to the discussion below:
http://boost.2283326.n4.nabble.com/Mixing-signals2-and-asio-mechanism-failing-tp4653392p4653403.html
To unsubscribe from Mixing signals2 and asio mechanism failing, click here.
NAML



--
------------
spandan sharma


View this message in context: Re: Mixing signals2 and asio mechanism failing
Sent from the Boost - Users mailing list archive at Nabble.com.