|
Boost Users : |
Subject: Re: [Boost-users] [asio]How to insure async handles not be called after calling deadline_timer::cancel()?
From: Michael Caisse (boost_at_[hidden])
Date: 2010-10-12 12:56:27
On 10/12/2010 12:19 AM, é«çå» wrote:
> The document says,
>
> If the timer has already expired when cancel() is called, then the
> handlers for asynchronous wait operations will:
>
> have already been invoked; or
> have been queued for invocation in the near future.
>
> These handlers can no longer be cancelled, and therefore are passed an
> error code that indicates the successful completion of the wait
> operation.
>
> Does this mean that async handlers may be called after calling
> deadline_timer::cancel() (say, the second curcumstance) ?
> If yes, it seems make things unintuitive, eg. delete the resources
> that associate with handlers after cancel().
> Is there any way to suppress or identify these handlers?
>
> thx.
> _______________________________________________
This is true for all handlers after an canceled async operation. Your
best course of action is to use shared_ptr and bind for handlers. In
particular, the normal pattern is to use shared_from_this with bind. The
result is lifetime management based on handler usage so you will be "safe".
You can find examples of this pattern as well as a "description" of the
proactor model in the ASIO boostcon slides found here:
<http://www.objectmodelingdesigns.com/boostcon10/>
michael
-- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net