Boost logo

Boost :

Subject: Re: [boost] [thread] sleep() with time_duration?
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-11-14 07:36:51


Boris <boriss_at_[hidden]> writes:

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

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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk