[thread] sleep() with time_duration?

If I want a thread to sleep for five seconds the shortest code I could come up with is: boost::system_time time = boost::get_system_time(); time += boost::posix_time::seconds(5); boost::thread::sleep(time); It would be nice if it was possible to pass a time_duration object to sleep() directly: boost::thread::sleep(boost::posix_time::seconds(5)); This would also be consistent with the deadline_timer in Boost.Asio whose constructor accepts both a time and a time_duration. Boris

----- Original Message ----- From: "Boris" <boriss@web.de> To: <boost@lists.boost.org> Sent: Friday, November 14, 2008 11:38 AM Subject: [boost] [thread] sleep() with time_duration?
Hi, I found your reques inline with the current proposal n2497 contains already this overloading http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html void sleep(const system_time& abs_t); template <class Duration> void sleep(const Duration& rel_t); There is also a more recent proposal N2651-A Foundation to Sleep On- Clocks, Points in Time, and Time Durations http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2615.html In it we found a proposal to update the thread library rename the sleep functions Threads The current time-related threading API is adapted to this proposal. An emphasis is put on ease of use, safety, efficiency, and durability with respect to advancing technology over time. Summary of changes: The parameters of the time-related functions have been modified to match the time API in this proposal. sleep(rel_time) has been renamed to sleep_for(rel_time). sleep(abs_time) has been renamed to sleep_until(abs_time). Particularly I prefer this renamming, but for compatibility purpose bouth shoul be implemented. Best, Vicente

Boris <boriss@web.de> writes:
boost::thread::sleep is only provided for backwards compatibility. boost::this_thread::sleep has the absolute time/duration overloads you desire: boost::this_thread::sleep(boost::posix_time::seconds(5)); Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Friday, November 14, 2008 1:36 PM Subject: Re: [boost] [thread] sleep() with time_duration?
The current proposal n2497 contains two overloadings http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html void boost::this_thread::sleep(const system_time& abs_t); template <class Duration> void boost::this_thread::sleep(const Duration& rel_t); Boost.Thread contains only the template <class Duration> void boost::this_thread::sleep(const Duration& rel_t); Could you add the other? Thanks, Vicente

On Nov 14, 2008, at 5:56 PM, vicente.botet wrote:
N2497 was overridden by N2661: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm#Threads_wo... This is all put together in the latest working draft: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf namespace std { namespace this_thread { template <class Clock, class Duration> void sleep_until(const chrono::time_point<Clock, Duration>& abs_time); template <class Rep, class Period> void sleep_for(const chrono::duration<Rep, Period>& rel_time); } } -Howard

----- Original Message ----- From: "Howard Hinnant" <hinnant@twcny.rr.com> To: <boost@lists.boost.org> Sent: Saturday, November 15, 2008 12:29 AM Subject: Re: [boost] [thread] sleep() with time_duration?
Yes, I know that, see my preceding post. But we don't have yet chrono in boost. Waiting for that maybe Anthony can add this template <class AbsoluteTime> void boost::this_thread::sleep_until(Time& abs_t); template <class Duration> void boost::this_thread::sleep_for(const Duration& rel_t); Vicente

On Nov 14, 2008, at 6:46 PM, vicente.botet wrote:
Ah, sorry 'bout that. You caught me skimming. :-)
But we don't have yet chrono in boost.
I'm probably skimming too fast again, but just in case you were too, Beman has this ready to go: See http://svn.boost.org/svn/boost/sandbox/chrono
I'll leave it Anthony (of course), but these signatures look overly generic to me (anything will bind to them). -Howard

----- Original Message ----- From: "Howard Hinnant" <hinnant@twcny.rr.com> To: <boost@lists.boost.org> Sent: Saturday, November 15, 2008 12:51 AM Subject: Re: [boost] [thread] sleep() with time_duration?
On Nov 14, 2008, at 6:46 PM, vicente.botet wrote:
I know also that ;-)
Please replace by void boost::this_thread::sleep_until(const system_time& abs_t); Best, Vicente
participants (4)
-
Anthony Williams
-
Boris
-
Howard Hinnant
-
vicente.botet