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