GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::this_thread::sleep_until(3) C++ Standard Libary std::this_thread::sleep_until(3)

std::this_thread::sleep_until - std::this_thread::sleep_until


Defined in header <thread>
template< class Clock, class Duration >
void sleep_until( const std::chrono::time_point<Clock,Duration>& (since C++11)
sleep_time );


Blocks the execution of the current thread until specified sleep_time has been
reached.


Clock must meet the Clock requirements.
The programs is ill-formed if std::chrono::is_clock_v<Clock> is false
(since C++20).


The standard recommends that the clock tied to sleep_time be used, in which case
adjustments of the clock may be taken into account. Thus, the duration of the block
might, but might not, be less or more than sleep_time - Clock::now() at the time of
the call, depending on the direction of the adjustment and whether it is honored by
the implementation. The function also may block for longer than until after
sleep_time has been reached due to scheduling or resource contention delays.


sleep_time - time to block until


(none)


Any exception thrown by Clock or Duration (clocks and durations provided by the
standard library never throw)

// Run this code


#include <iostream>
#include <chrono>
#include <thread>


auto now() { return std::chrono::steady_clock::now(); }


auto awake_time() {
using std::chrono::operator""ms;
return now() + 2000ms;
}


int main()
{
std::cout << "Hello, waiter...\n" << std::flush;
const auto start {now()};
std::this_thread::sleep_until(awake_time());
std::chrono::duration<double, std::milli> elapsed {now() - start};
std::cout << "Waited " << elapsed.count() << " ms\n";
}


Hello, waiter...
Waited 2000.17 ms


sleep_for stops the execution of the current thread for a specified time duration
(C++11) (function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.