Discussion:
asio timer not fired on release version
(too old to reply)
Bruce
2017-04-28 03:02:43 UTC
Permalink
Hi,


In my program I write a timer which start 3 seconds later. I used in in debug version and it works fine. But after I switch to release version, it don't work anymore. Just not fire.


The codes I set the timer:


ret = m_timer.expires_from_now(std::chrono::seconds(3));
m_timer.async_wait(boost::bind(&qmInnerTimer::Fire, this, _1));



The codes in Fire:
void qmInnerTimer::
Fire(const boost::system::error_code &ec)
{
if (ec == boost::asio::error::operation_aborted)
{
XM_TRADELOG_INFO("Handler1: Timer 1 was cancelled or retriggered.");
}
else
{
XM_TRADELOG_INFO("Release: timer fired");
}
}



I use vs2015 and compile with /MDd with debug version and /MD with release version.


Any suggestions?
Thanks
Igor Solovyov
2017-04-28 09:32:24 UTC
Permalink
Hi Bruce,

In your not complete example I see the "this" usage in a bind. So I suspect
your object instance cloud be destroyed earlier than timer callback is
invoked.
You have to double check your object lifetime. BTW it's a quite often
mistake of Asio newbies:)

Regards,
I.
Post by Bruce
Hi,
In my program I write a timer which start 3 seconds later. I used in in
debug version and it works fine. But after I switch to release version, it
don't work anymore. Just not fire.
ret = m_timer.expires_from_now(std::chrono::seconds(3));
m_timer.async_wait(boost::bind(&qmInnerTimer::Fire, this, _1));
Fire(const boost::system::error_code &ec)
{
if (ec == boost::asio::error::operation_aborted)
{
XM_TRADELOG_INFO("Handler1: Timer 1 was cancelled or retriggered.");
}
else
{
XM_TRADELOG_INFO("Release: timer fired");
}
}
I use vs2015 and compile with /MDd with debug version and /MD with release version.
Any suggestions?
Thanks
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
ivan kostov
2017-04-28 10:38:19 UTC
Permalink
Hi Bruce,

maybe Igor is right ;).

Be careful when using *this. Prefer shared_ptr instead and have a look in
the std::enable_shared_from_this manual.
The idea is that when you have async framework you are not sure when you
can destruct an object. The only one which knows this is the async handler.
So ... instead of destroying the object explicitly, use shared_ptr. This is
what makes Java developers jealous :D

Cheers,
Ivan
Post by Igor Solovyov
Hi Bruce,
In your not complete example I see the "this" usage in a bind. So I
suspect your object instance cloud be destroyed earlier than timer callback
is invoked.
You have to double check your object lifetime. BTW it's a quite often
mistake of Asio newbies:)
Regards,
I.
Post by Bruce
Hi,
In my program I write a timer which start 3 seconds later. I used in in
debug version and it works fine. But after I switch to release version, it
don't work anymore. Just not fire.
ret = m_timer.expires_from_now(std::chrono::seconds(3));
m_timer.async_wait(boost::bind(&qmInnerTimer::Fire, this, _1));
Fire(const boost::system::error_code &ec)
{
if (ec == boost::asio::error::operation_aborted)
{
XM_TRADELOG_INFO("Handler1: Timer 1 was cancelled or retriggered.");
}
else
{
XM_TRADELOG_INFO("Release: timer fired");
}
}
I use vs2015 and compile with /MDd with debug version and /MD with release version.
Any suggestions?
Thanks
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Loading...