std::latch::try_wait(3)

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

πŸ’… std::latch::try_wait(3) β€” from the C++ Standard Libary manual ✨

okay bestie, we’re in the C++ Standard Libary manual and this page is all about std::latch::try_wait(3). no cap, it’s a tiny little function but the details matter, so let’s get into it 🫢


πŸŽ€ NAME πŸŽ€

std::latch::try_wait β€” yep, that’s the name, and also the other name: std::latch::try_wait. iconic repetition, honestly πŸ’…


✨ Synopsis ✨

bool try_wait() const noexcept;  (since C++20)

This one returns true only if the internal counter has reached zero. but bestie, listen: this function may spuriously return false with very low probability even if the internal counter has reached zero. so yeah, it’s usually giving β€œcounter check,” but there’s a tiny β€œmaybe not” vibe 😭


🌸 Parameters 🌸

  • (none) β€” literally no parameters, bestie. zero. nada. nothing to pass in πŸŽ€

πŸ¦‹ Return value πŸ¦‹

With very low probability false; otherwise cnt == 0, where cnt is the value of the internal counter. that’s the whole return-value situation, and yes, the cnt == 0 part is important πŸ‘‘


πŸ’œ Notes πŸ’œ

The reason why a spurious result is permitted is to allow implementations to use a memory order more relaxed than std::memory_order_seq_cst. so it’s not chaos for no reason β€” it’s a tradeoff for implementations, iykyk 🌈


🌟 that’s the page, bestie. source: http://cppreference.com; date/version: 2024.06.10; page: std::latch::try_wait(3) β€” mwah, bye πŸ’–
πŸ“¦ where this page comes from