[Boost-users] How to use boost::thread::sleep(...)?

2,554 views
Skip to first unread message

Jean-Sebastien Stoezel

unread,
Jul 5, 2008, 1:51:05 PM7/5/08
to boost...@lists.boost.org
Hi,

I would like to relinquish the CPU from a thread so I thought using
boost::thread::sleep(...). However, I have no idea how to initialize
its argument. It looks like this is a boost::system_time. How to
initiliaze such a type so my thread waits 20ms, 100ms...!?

Thanks!
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Anthony Williams

unread,
Jul 5, 2008, 4:20:24 PM7/5/08
to boost...@lists.boost.org
Jean-Sebastien Stoezel <js.st...@gmail.com> writes:

> I would like to relinquish the CPU from a thread so I thought using
> boost::thread::sleep(...). However, I have no idea how to initialize
> its argument. It looks like this is a boost::system_time. How to
> initiliaze such a type so my thread waits 20ms, 100ms...!?

You can use

boost::thread::sleep(boost::get_system_time()+boost::posix_time::milliseconds(20));

or use the new this_thread namespace version of sleep:

boost::this_thread::sleep(boost::posix_time::milliseconds(20));

Anthony
--
Anthony Williams | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

Jean-Sebastien Stoezel

unread,
Jul 5, 2008, 5:17:14 PM7/5/08
to boost...@lists.boost.org
Great thanks!

Peter Klotz

unread,
Jul 5, 2008, 5:34:19 PM7/5/08
to boost...@lists.boost.org

Just use

#include <boost/thread/thread.hpp>

boost::this_thread::sleep(boost::posix_time::milliseconds(20));

Best regards, Peter.

Reply all
Reply to author
Forward
0 new messages