|
Boost Users : |
Subject: Re: [Boost-users] asio::async_write
From: Juraj IvanÄiÄ (juraj.ivancic_at_[hidden])
Date: 2009-11-18 11:54:24
Lloyd wrote:
>> Creating asynchronous operation handlers on stack does not make much
>> sense.
>>
>
> Why do you say this? Is there any chance of crashing the application?
Correction of my previous statement: It does not make sense to pass
member function bound to a stack allocated object as an asynchronous
operation handler.
Passed handler must remain valid until async operation is completed
i.e. until it gets called. The shared_ptr trick is a way to ensure that,
because handler itself owns a shared pointer to the object in question
thus assuring its still valid.
Your example is perfectly safe because it will do nothing - you are not
running io_service in a separate thread, so async operation will never
even start.
You might want to have a look at asynchronous examples in asio
documentation.
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