An absolute timeout sets a deadline at a particular point on a clock’s timeline. Unlike a duration-based timeout, which specifies how long to wait, it says when to stop waiting. C++ waiting functions commonly distinguish the forms with `_until` and `_for` suffixes. section 4.3
A deadline is a `std::chrono::time_point` associated with a clock. Adding a duration to `some_clock::now()` creates a deadline; reusing that point across multiple waits keeps them within one time budget. The clock matters: adjustments can shorten or lengthen the wait as measured by a steady clock. section 4.3.3
Listing 4.11. Waiting for a condition variable with a timeout
#include <condition_variable>
#include <mutex>
#include <chrono>
std::condition_variable cv;
bool done;
std::mutex m;
bool wait_loop()
{
auto const timeout= std::chrono::steady_clock::now()+
std::chrono::milliseconds(500);
std::unique_lock<std::mutex> lk(m);
while(!done)
{
if(cv.wait_until(lk,timeout)==std::cv_status::timeout)
break;
}
return done;
}
This condition-variable loop calculates one steady-clock deadline 500 milliseconds ahead and reuses it while checking whether the wait has completed. section 4.3.3
