36 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// ALLOW_RETRIES: 312 13// <thread>14 15// template <class Rep, class Period>16// void sleep_for(const chrono::duration<Rep, Period>& rel_time);17 18#include <thread>19#include <cassert>20#include <chrono>21 22int main(int, char**)23{24 typedef std::chrono::system_clock Clock;25 typedef Clock::time_point time_point;26 std::chrono::milliseconds ms(500);27 time_point t0 = Clock::now();28 std::this_thread::sleep_for(ms);29 time_point t1 = Clock::now();30 // NOTE: Operating systems are (by default) best effort and therefore we may31 // have slept longer, perhaps much longer than we requested.32 assert(t1 - t0 >= ms);33 34 return 0;35}36