Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame^] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 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 | |
| 19 | int 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 | } |