你好我有一个间隔计时器,我希望它终止而不等待它的间隔终止。我该怎么做? 我已经尝试用读数标志控制该功能。一旦读取标志设置为停止,我希望函数退出而不用等待间隔计时器的一次迭代才能退出。
void send_poll()
{
// Schedule the timer for the first time:
timer.async_wait(poll_device);
// Enter IO loop. The timer will fire for the first time 1 second from now:
io_service.run();
}
void poll_device(const boost::system::error_code& /*e*/)
{
std:: cout << "message being polled" << std::endl;
// do polling of device
if (reading_flag!=1)
{
std::terminate();
}
// Reschedule the timer for 1 second in the future:
timer.expires_at(timer.expires_at() + interval);
// Posts the timer event
timer.async_wait(poll_device)
}