blob: c0bf087c6faa763751fbe13498921a2274240e0c [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <thread>
11
12// template <class Clock, class Duration>
13// void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
14
15#include <thread>
16#include <cstdlib>
17#include <cassert>
18
19int main()
20{
21 typedef std::chrono::system_clock Clock;
22 typedef Clock::time_point time_point;
23 typedef Clock::duration duration;
24 std::chrono::milliseconds ms(500);
25 time_point t0 = Clock::now();
26 std::this_thread::sleep_until(t0 + ms);
27 time_point t1 = Clock::now();
28 std::chrono::nanoseconds ns = (t1 - t0) - ms;
29 std::chrono::nanoseconds err = ms / 100;
30 // The time slept is within 1% of 500ms
31 assert(std::abs(ns.count()) < err.count());
32}