8

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?

2NinerRomeo
  • 2,687
  • 4
  • 29
  • 35
  • I should have mentioned that I would like to sleep for a period of milliseconds, rather than seconds. I have tried passing in the following arguments: `boost::chrono::milliseconds(10)` `boost::chrono::duration(10)` – 2NinerRomeo Mar 05 '12 at 17:09
  • I am waiting for this feature since chrono has been added to boost...i hope it will finally make it into the next release! – moka Mar 21 '12 at 16:15

1 Answers1

12

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.

J.N.
  • 8,203
  • 3
  • 29
  • 39
  • I'm getting `error C2039: 'sleep_for' : is not a member of 'boost::this_thread'` I've missed things before, but I don't see it in the documentation for 'this_thread' [http://www.boost.org/doc/libs/1_49_0/doc/html/thread/thread_management.html] although it does appear that it may be part of std::this_thread in C++11. – 2NinerRomeo Mar 05 '12 at 17:17
  • I can't confirm immediately, but I may have mentioned a feature in the boost development tree, not the release (it compiled fine for me). I'll try and check a bit later today, all my apologies. – J.N. Mar 05 '12 at 22:19
  • @2NinerRomeo : my bad, it wasn't released feature yet. Sorry again. – J.N. Mar 06 '12 at 12:05