Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sleep with boost::chrono?

Examples of boost::this_thread::sleep() seem to use objects of boost::posix_time::milliseconds. I've tried that and it works, but I am using boost::chrono for checking the system clock etcetera. It seems to me I should be able to pass sleep() a chrono::duration like this:

boost::this_thread::sleep( boost::chrono::duration(10) );

But the compiler is giving me the following error:

... boost_1_49_0\boost/thread/win32/thread_data.hpp(171) : error C2039: 'total_milliseconds' : is not a member of 'boost::chrono::duration'

Which I find confusing. Am I right in thinking I should be able to do this? Will it be necessary to convert to a posix_time?

like image 878
2NinerRomeo Avatar asked Mar 03 '12 01:03

2NinerRomeo


People also ask

What is boost :: Chrono?

boost::chrono::system_clock returns the system time. This is the time usually displayed on the desktop of your computer. If you change the time on your computer, boost::chrono::system_clock returns the new time.


1 Answers

Like this, use sleep_for and seconds

boost::this_thread::sleep_for( boost::chrono::seconds(10) );

EDIT

After verification this feature is not yet available in boost 1.49.0. All my apologies. This is only working in the trunk version of boost.

That means that it is not possible to call a sleep-like function without converting to a boost.datetime format.

like image 169
J.N. Avatar answered Sep 20 '22 00:09

J.N.