Re: [asio-users] this vs shared_from_this() in examples
Brought to you by:
chris_kohlhoff
From: Gruenke, M. <mgruenke@Tycoint.com> - 2012-02-21 18:39:17
|
Well, if you're using io_service::stop(), you'd better wait until the thread(s) calling run() or run_one() return! The third condition would be that all of your operations have been canceled & the corresponding handler has been called (keep in mind that it may receive canceled or any other status). The approach I use is to post an operation to my io_service (actually, to the strand running each state machine) that cancels the outstanding operations. Then, instead of calling io_service::stop(), I kill io_service::work and let the thread(s) calling io_service::run() return by themselves, which happens when all of the outstanding operations have completed or been canceled. Once that has happened, you can proceed to tear down all the objects on which your handlers have been operating (unless you bound shared_ptr's to them, which would do this automatically). Matt -----Original Message----- From: Amir Taaki [mailto:zg...@ya...] Sent: Tuesday, February 21, 2012 13:05 To: asi...@li... Subject: Re: [asio-users] this vs shared_from_this() in examples OK thanks Igor and Yuri. I understand now. Basically io_service::stop() or the io_service must go out of scope before the class destructor (for which the methods are bound) is called. That ensures no methods tried to get call with a destroyed object. |