Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Date and Time Requirements

Typedef system_time
Non-member function get_system_time()

As of Boost 1.35.0, the Boost.Thread library uses the Boost.Date_Time library for all operations that require a time out. These include (but are not limited to):

For the overloads that accept an absolute time parameter, an object of type boost::system_time is required. Typically, this will be obtained by adding a duration to the current time, obtained with a call to boost::get_system_time(). e.g.

boost::system_time const timeout=boost::get_system_time() + boost::posix_time::milliseconds(500);

extern bool done;
extern boost::mutex m;
extern boost::condition_variable cond;

boost::unique_lock<boost::mutex> lk(m);
while(!done)
{
    if(!cond.timed_wait(lk,timeout))
    {
        throw "timed out";
    }
}

For the overloads that accept a TimeDuration parameter, an object of any type that meets the Boost.Date_Time Time Duration requirements can be used, e.g.

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

boost::mutex m;
if(m.timed_lock(boost::posix_time::nanoseconds(100)))
{
    //  ...
}
#include <boost/thread/thread_time.hpp>

typedef boost::posix_time::ptime system_time;

See the documentation for boost::posix_time::ptime in the Boost.Date_Time library.

#include <boost/thread/thread_time.hpp>

system_time get_system_time();

Returns:

The current time.

Throws:

Nothing.


PrevUpHomeNext