std::counti...quire_until(3)
π NAME π
Okay so bestie, welcome to the std::counti...quire_until(3) page from the C++ Standard Libary manual. The star of the show is std::counting_semaphore::try_acquire_until β yes, that's the whole NAME, and the page absolutely repeats it because why not π
.
β¨ Synopsis β¨
Here's the signature, copied exactly. The (since C++20) annotation is called out separately because she's iconic:
template< class Clock, class Duration >
bool try_acquire_until( const std::chrono::time_point<Clock,
Duration>& abs_time );
(since C++20) β this one is a C++20 girlie, no cap.
What it does: it tries to atomically decrement the internal counter by 1 if it's greater than 0. If it's not, it blocks until the counter is greater than 0 and it can successfully decrement the internal counter, or until the abs_time time point has been passed. It's giving "wait for the right moment" energy π«Ά.
And heads up: the program is ill-formed if std::chrono::is_clock_v<Clock> is false. Like, compiler says nope π.
π¦ Preconditions π¦
Clock has to meet the Clock requirements. Periodt.
π Parameters π
abs_timeβ the earliest time the function must wait until in order to fail.
π«Ά Return value π«Ά
true if it decremented the internal counter, otherwise false. Simple, clean, slay.
π Exceptions π
It may throw std::system_error or a timeout-related exception. So yeah, she can get dramatic.
π Notes π
In practice, the function may take longer than abs_time to fail. Not her being late on purpose, it's just literally how it is π.
π See also π
releaseβ increments the internal counter and unblocks acquirers (public member function).acquireβ decrements the internal counter or blocks until it can (public member function).try_acquireβ tries to decrement the internal counter without blocking (public member function).try_acquire_forβ tries to decrement the internal counter, blocking for up to a duration time (public member function).
source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::counti...quire_until(3). bye bestie, go decrement those counters responsibly π
β¨πΈ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms