
The only functions I'm binding with boost::bind are members of
ClassifierContext, eg:
ICMessage::async_read(socket_,
boost::bind(&ClassifierContext::handleCmdMsg,
this,
_1,_2,_3));
Since the io_service object is stopped in the destructor of
ClassifierContext, shouldn't that be OK? Or should
I still try to create a shared_from_this off of the ClassifierContext class?
On Thu, Mar 18, 2010 at 11:50 PM, Rutger ter Borg
Sean McAllister wrote:
Not using a shared_ptr_from_this, but I am using shared_ptr wrapped objects as parameters to my asynchronous callbacks...
If you use patterns like
boost::bind( &some_class::some_mem_fn, this, .... )
then it could be that the instance of some_class is destructed before the bind-expression is. If the handler is called with "operation cancelled" (which should happen with all waiting handlers if you call io_service.stop()), it tries to make a call into freed memory -- you can expect a crash, indeed. To solve this, one can use shared_from_this(),
boost::bind( &some_class::some_mem_fn, shared_from_this(), .... )
to make sure the object's lifetime will be at least that of the incomplete handler.
Cheers,
Rutger
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users