How to sleep with boost :: chrono?

The boost::this_thread::sleep() examples seem to use boost::posix_time::milliseconds objects. I tried this and it works, but I use boost::chrono to check the system clock, etc. It seems to me that I should go through sleep() a chrono::duration as follows:

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

But the compiler tells 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'

What I find embarrassed. Am I right in thinking that I can do this? Will it be necessary to convert to posix_time ?

+8
c ++ chrono boost-thread
source share
1 answer

In this case use sleep_for and seconds

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

EDIT

After checking, this function is not yet available in boost 1.49.0. All my apologies. This only works in boost version.

This means that it is impossible to call a function such as sleep mode without converting to boost.datetime format.

+11
source share

All Articles