sleep_for.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <thread> 11 12// template <class Rep, class Period> 13// void sleep_for(const chrono::duration<Rep, Period>& rel_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_for(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} 33