Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can the boost::asio timer object be deleted before the corresponding callback is called?

Should the timer object exist until the task is completed?

I mean the following:

boost::asio::io_service io;

{
    boost::asio::steady_timer timer(io, std::chrono::seconds(5));
    timer.async_wait(someCallback);
} // the timer object is deleted here

io.run();

Is this allowed and does it lead to undefined behavior?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The destructor simply cancels any pending waits so your callback will be called with the boost::asio::error::operation_aborted error code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading