std::counti...try_acquire(3)
π NAME π
okay so bestie, weβre in the C++ Standard Libary manual β yes, thatβs literally how the header spells it, iconic β and this page is about std::counting_semaphore::try_acquire. The header title is std::counti...try_acquire(3) because terminal truncation said what it said π, and the NAME section just repeats std::counting_semaphore::try_acquire. No cap, thatβs the whole name.
β¨ SYNOPSIS β¨
bool try_acquire() noexcept; (since C++20)
It tries to atomically decrement the internal counter by 1 if it is greater than 0; no blocking occurs regardless. Literally zero blocking, even if it fails. π¦
π RETURN VALUE π
true if it decremented the internal counter, otherwise false. Thatβs it. Periodt. π₯
π§ NOTES π§
Implementations are allowed to fail to decrement the counter even if it was greater than 0 β i.e., they are allowed to spuriously fail and return false. So bestie, spurious failure is a whole allowed vibe: even when the counter was greater than 0, an implementation can fail to decrement and hand you back false. π
π 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_forβ tries to decrement the internal counter, blocking for up to a duration time (public member function). β³try_acquire_untilβ tries to decrement the internal counter, blocking until a point in time (public member function). π°οΈ
source/version sign-off: http://cppreference.com, dated 2024.06.10 β mwah, bestie ππ
π¦ 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