| Home | Libraries | People | FAQ | More

## Time Requirements

As of Boost 1.50.0, the Boost.Thread library uses Boost.Chrono library for all operations that require a time out as defined in the standard c++11. These include (but are not limited to):

- `boost::this_thread::`sleep_for``
- `boost::this_thread::`sleep_until``
- `boost::`thread`::`try_join_for``
- `boost::`thread`::`try_join_until``
- `boost::`condition_variable`::`wait_for``
- `boost::`condition_variable`::`wait_until``
- `boost::`condition_variable_any`::`wait_for``
- `boost::`condition_variable_any`::`wait_until``
- ``TimedLockable` ::`try_lock_for``
- ``TimedLockable` ::`try_lock_until``

### Deprecated

The time related functions introduced in Boost 1.35.0, using the Boost.Date_Time library are deprecated. These include (but are not limited to):

- `boost::this_thread::sleep()`
- `timed_join()`
- `timed_wait()`
- `timed_lock()`

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)))
    {
        //  ...
    }

#### Typedef `system_time`

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

#### Non-member function `get_system_time()`

    #include <boost/thread/thread_time.hpp>

    system_time get_system_time();

Returns:

  The current time.

Throws:

  Nothing.