1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: libcpp-has-no-threads
10 
11 // Until 58a0a70fb2f1, this_thread::sleep_for could sometimes get interrupted
12 // by signals and this test would fail spuriously. Disable the test on the
13 // corresponding system libraries.
14 // UNSUPPORTED: with_system_cxx_lib=macosx10.11
15 // UNSUPPORTED: with_system_cxx_lib=macosx10.10
16 // UNSUPPORTED: with_system_cxx_lib=macosx10.9
17 
18 // <thread>
19 
20 // template <class Rep, class Period>
21 //   void sleep_for(const chrono::duration<Rep, Period>& rel_time);
22 
23 #include <thread>
24 #include <cassert>
25 #include <chrono>
26 
main(int,char **)27 int main(int, char**)
28 {
29   typedef std::chrono::system_clock Clock;
30   typedef Clock::time_point time_point;
31   std::chrono::milliseconds ms(500);
32   time_point t0 = Clock::now();
33   std::this_thread::sleep_for(ms);
34   time_point t1 = Clock::now();
35   // NOTE: Operating systems are (by default) best effort and therefore we may
36   // have slept longer, perhaps much longer than we requested.
37   assert(t1 - t0 >= ms);
38 
39   return 0;
40 }
41