xref: /llvm-project/libcxx/test/std/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp (revision a55632a069d89804938d7ef33192888f539b3bc8)
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 // TODO(ldionne): This test fails on Ubuntu Focal on our CI nodes (and only there), in 32 bit mode.
12 // UNSUPPORTED: linux && 32bits-on-64bits
13 
14 // <thread>
15 
16 // template <class Clock, class Duration>
17 //   void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
18 
19 #include <thread>
20 #include <cstdlib>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 
25 int main(int, char**)
26 {
27   typedef std::chrono::system_clock Clock;
28   typedef Clock::time_point time_point;
29   std::chrono::milliseconds ms(500);
30   time_point t0 = Clock::now();
31   std::this_thread::sleep_until(t0 + ms);
32   time_point t1 = Clock::now();
33   // NOTE: Operating systems are (by default) best effort and therefore we may
34   // have slept longer, perhaps much longer than we requested.
35   assert(t1 - t0 >= ms);
36 
37   return 0;
38 }
39