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 typedef Clock::duration duration; 26 std::chrono::milliseconds ms(500); 27 time_point t0 = Clock::now(); 28 std::this_thread::sleep_until(t0 + ms); 29 time_point t1 = Clock::now(); 30 std::chrono::nanoseconds ns = (t1 - t0) - ms; 31 std::chrono::nanoseconds err = 5 * ms / 100; 32 // The time slept is within 5% of 500ms 33 assert(std::abs(ns.count()) < err.count()); 34 } 35