# Boost.Threads - Header <boost/thread/xtime.hpp>

###

# Boost.Threads

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

## Contents

Introduction
Values

TIME_UTC

Classes

Struct `xtime`

Struct `xtime` synopsis

Functions

`xtime_get`

Example(s)

## Introduction

The header <boost/thread/xtime.hpp> defines functions and data types used to perform high-resolution time operations. This is a temporary solution that will be replaced by a more robust time library once available in Boost.

## Values

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

## Classes

### Struct `xtime`

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 (or some other time library) will be provided in Boost as a separate library, at which time Boost.Threads will deprecate its implementation.

#### Struct `xtime` synopsis

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

## Functions

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

Postconditions: `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.
Note: 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(s)

    #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-2002. All Rights Reserved.

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. William E. Kempf makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.