std::counti...try_acquire(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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