brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 7a08065 Raw
37 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10 11// <thread>12 13// template <class Clock, class Duration>14//   void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);15 16#include <cassert>17#include <chrono>18#include <cstdlib>19#include <thread>20 21#include "test_macros.h"22 23int main(int, char**)24{25  typedef std::chrono::system_clock Clock;26  typedef Clock::time_point time_point;27  std::chrono::milliseconds ms(500);28  time_point t0 = Clock::now();29  std::this_thread::sleep_until(t0 + ms);30  time_point t1 = Clock::now();31  // NOTE: Operating systems are (by default) best effort and therefore we may32  // have slept longer, perhaps much longer than we requested.33  assert(t1 - t0 >= ms);34 35  return 0;36}37