Home | History | Annotate | Download | only in thread.thread.this
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // UNSUPPORTED: libcpp-has-no-threads
     11 
     12 // <thread>
     13 
     14 // template <class Clock, class Duration>
     15 //   void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
     16 
     17 #include <thread>
     18 #include <cstdlib>
     19 #include <cassert>
     20 
     21 int main()
     22 {
     23     typedef std::chrono::system_clock Clock;
     24     typedef Clock::time_point time_point;
     25     std::chrono::milliseconds ms(500);
     26     time_point t0 = Clock::now();
     27     std::this_thread::sleep_until(t0 + ms);
     28     time_point t1 = Clock::now();
     29     std::chrono::nanoseconds ns = (t1 - t0) - ms;
     30     std::chrono::nanoseconds err = 5 * ms / 100;
     31     // The time slept is within 5% of 500ms
     32     assert(std::abs(ns.count()) < err.count());
     33 }
     34