[완료] boost::timer와 boost::asio::deadline_timer
글쓴이: kukyakya / 작성시간: 목, 2009/07/23 - 6:24오전
#include <iostream> #include <boost/timer.hpp> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> int main(int argc, char *argv[]) { boost::asio::io_service io; boost::timer ti; boost::asio::deadline_timer dt(io, boost::posix_time::seconds(2)); dt.wait(); std::cout << ti.elapsed() << " seconds" << std::endl; return 0; }
위와 같은 소스를 g++ a.cpp -lboost_system -lpthread 로 컴파일하고 실행하면 2초 후에 0 seconds라고 출력이 됩니다. 2초 후에 2 seconds가 출력되길 기대했는데 이유를 잘 모르겠습니다.
구글링을 해봐도 마땅히 검색되는 글이 없어 헤매고 있습니다. 답변을 부탁드려요
Forums:
boost/timer.hpp를 까보니
이 놈은 clock()을 써서 구현이 되어 있더군요. cpu time을 소비하지 않는 sleep계열은
elapsed가 0으로 나올 수 밖에 없습니다. 의도하신 것이 순수한 경과된 시간을 구하는 것이라면
다른 방법을 사용하셔야 할 듯 하네요.
답변 감사합니다.
답변 감사합니다.
음...
요즘 최신 Boost 라이브러리로 해보면 잘 나옵니다.
중간에 패치된 듯 하네요.
댓글 달기