Discussion:
how to sleep a thread for specified milliseconds and/or nanoseconds
Victor Whiskey Yankee
2008-05-19 15:20:39 UTC
Permalink
Hello,
I'm using boost 1.35.

Would someone please give example of best way to sleep for a specified
duration of milliseconds or nanoseconds?

It seems that xtime is being deprecated in the thread library, but the
sleep function still wants an xtime?

Thanks,
Victor
Kevin Heifner
2008-05-19 15:39:19 UTC
Permalink
Post by Victor Whiskey Yankee
I'm using boost 1.35.
Would someone please give example of best way to sleep for a specified
duration of milliseconds or nanoseconds?
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
boost::this_thread::sleep(boost::posix_time::nanoseconds(10));
Post by Victor Whiskey Yankee
It seems that xtime is being deprecated in the thread library, but the
sleep function still wants an xtime?
Yes, xtime is deprecated.

KevinH
--
Kevin Heifner heifner @ ociweb.com http://heifner.blogspot.com
Object Computing, Inc. (OCI) www.ociweb.com
Victor Whiskey Yankee
2008-05-19 15:55:04 UTC
Permalink
_______________________________________________
Boost-users mailing list
Boost-***@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Scott McMurray
2008-05-19 15:58:29 UTC
Permalink
On Mon, May 19, 2008 at 11:55 AM, Victor Whiskey Yankee
Great.Thank you!
Now, how can I sleep if I am not inside a boost::thread? When I try that, I
error: 'boost::this_thread' has not been declared
You can't not be in a thread. And that error usually means a missing include.

http://www.boost.org/doc/libs/1_35_0/doc/html/thread/thread_management.html#thread.thread_management.this_thread.sleep
Victor Whiskey Yankee
2008-05-19 16:15:00 UTC
Permalink
_______________________________________________
Boost-users mailing list
Boost-***@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Igor R.
2008-05-19 16:26:53 UTC
Permalink
You mean there is not a sleep function anywhere in boost but inside boost::thread? Wow...that's incredible disappointment.
sleep() resides in this_thread namespace
just include the appropriate header file
_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx
Victor Whiskey Yankee
2008-05-19 16:47:13 UTC
Permalink
_______________________________________________
Boost-users mailing list
Boost-***@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Anthony Williams
2008-05-19 16:37:21 UTC
Permalink
Post by Scott McMurray
Now, how can I sleep if I am not inside a boost::thread? When I try that, I
error: 'boost::this_thread' has not been declared
You can't not be in a thread. And that error usually means a missing include.
You mean there is not a sleep function anywhere in boost but inside
boost::thread? Wow...that's incredible disappointment.<br>
Maybe with signals or condition variable by chance?<br>
How does one sleep in main that allows milliseconds and is
cross-platform with linux and windows xp?
boost::this_thread::sleep works in all threads, including those not started
with boost::thread, such as main.

However, you need to include the right header:

#include <boost/thread/thread.hpp>

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
Anthony Williams
2008-05-19 15:40:27 UTC
Permalink
Post by Victor Whiskey Yankee
Would someone please give example of best way to sleep for a specified
duration of milliseconds or nanoseconds?
boost::this_thread::sleep(boost::posix_time::milliseconds(3));

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
Loading...