# Boost.Threads, xtime
Keywords: threads, Boost.Threads, thread library, C++

###

# Boost.Threads

## xtime

Introduction
Header
Synopsis
Reference
Example

## Introduction

The `xtime` type is used to represent a point on some time scale or a duration in time. This type may be proposed for the C standard by Markus Kuhn. Boost.Threads provides only a very minimal implementation of this proposal and it's expected that a full implementation will be provided in Boost as a separate library, at which time Boost.Threads will deprecate its implementation.

## Header

    #include <boost/thread/xtime.hpp>

## Synopsis

    namespace boost {

    enum
    {
       TIME_UTC=1,
    };

    struct xtime
    {
    #if defined(BOOST_NO_INT64_T)
       int_fast32_t sec;
    #else
       int_fast64_t sec;
    #endif
       int_fast32_t nsec;
    };

    int xtime_get(struct xtime* xtp, int clock_type);

    } // namespace boost

## Reference

### TIME_UTC

The clock type for Coordinated Universal Time (UTC). The epoch for this clock type is 1970-01-01 00:00:00. This is the only clock type supported by Boost.Threads.

### xtime

       struct xtime
       {
    #if defined(BOOST_NO_INT64_T)
          int_fast32_t sec;
    #else
          int_fast64_t sec;
    #endif
          int_fast32_t nsec;
       };

sec represents the whole seconds that have passed since the epoch.

nsec represents the nanoseconds since `sec.`

### xtime_get

       int xtime_get(struct xtime* xtp, int clock_type);

Postcondition: `xtp` represents the current point in time as a duration since the epoch specified by the `clock_type`.

Returns: `clock_type` if successful, otherwise 0.

Notes: The resolution is implementation specific. For many implementations the best resolution of time is far more than one nanosecond, and even when the resolution is reasonably good, the latency of a call to `xtime_get()` may be significant. For maximum portability, avoid durations of less than one second.

## Example Usage

    #include <boost/thread/thread.hpp>
    #include <boost/thread/xtime.hpp>

    int main(int argc, char* argv[])
    {
       boost::xtime xt;
       boost::xtime_get(&xt, boost::TIME_UTC);
       xt.sec += 1;
       boost::thread::sleep(xt); // Sleep for 1 second
    }

Revised 05 November, 2001

© Copyright William E. Kempf 2001 all rights reserved.