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 // FLAKY_TEST. 12 13 // <thread> 14 15 // template <class Clock, class Duration> 16 // void sleep_until(const chrono::time_point<Clock, Duration>& abs_time); 17 18 #include <thread> 19 #include <cstdlib> 20 #include <cassert> 21 main()22int main() 23 { 24 typedef std::chrono::system_clock Clock; 25 typedef Clock::time_point time_point; 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