boost::asio::steady_timer 의 잘못된 용법
1927 단어 Boost
// boost.chrono std.chrono,
#define BOOST_ASIO_DISABLE_STD_CHRONO
#include
#include
#include
#include
#include
bool g_isExit = false;
void DoSth(int idx, const boost::system::error_code& errCode)
{
if (errCode)
{
std::string str = (boost::format("idx=%|d|, value=%|d|, message=%|s|") % idx%errCode.value() % errCode.message()).str();
std::cout << str << std::endl;
return;
}
else
{
std::string str = (boost::format("idx=%|d|, doing") % idx).str();
std::cout << str << std::endl;
}
boost::this_thread::sleep_for(boost::chrono::seconds(3));// , 3 ,
g_isExit = true;
return;
}
int main(int argc, char** argv)
{
boost::thread_group thgp;
boost::asio::io_service io;
boost::asio::io_service::work wk(io);
thgp.create_thread(boost::bind(&boost::asio::io_service::run, boost::ref(io)));
thgp.create_thread(boost::bind(&boost::asio::io_service::run, boost::ref(io)));
boost::asio::steady_timer timer(io);
//boost::asio::steady_timer , 1000ms ,
timer.expires_from_now(boost::chrono::milliseconds(1000));
timer.async_wait(boost::bind(&DoSth, 1, boost::asio::placeholders::error));
// , , ,
// : value=995, message= , I/O 。
timer.expires_from_now(boost::chrono::milliseconds(1000));
timer.async_wait(boost::bind(&DoSth, 2, boost::asio::placeholders::error));
while (false == g_isExit)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
}
std::cout << "press ENTER to exit..." << std::endl;
std::cin.sync();
while (getchar() != '
') {}
}
끝나다