std::atomic_flag::wait(3)

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

πŸ¦‹ std::atomic_flag::wait(3) πŸ¦‹

okay so bestie, welcome to the C++ Standard Libary manual page for std::atomic_flag::wait β€” yes, the manual name is folded right in here, and the group chat is open. πŸ’…βœ¨


🌸 NAME 🌸

std::atomic_flag::wait - std::atomic_flag::wait

literally the name is the same thing twice, and that's iconic. periodt. πŸ‘‘


✨ Synopsis ✨

void wait( bool old, std::memory_order order =
                         std::memory_order::seq_cst ) const
(1) (since C++20)
noexcept;
void wait( bool old, std::memory_order order =
                         std::memory_order::seq_cst ) const
(2) (since C++20)
volatile noexcept;

bestie, these are atomic waiting operations 😭 and the vibe is: it behaves as if it repeatedly does this little loop:

  • Compare this->test(order) with that of old.
    • If those are equal, then blocks until *this is notified by notify_one() or notify_all(), or the thread is unblocked spuriously.
    • Otherwise, returns.

no cap: these functions are guaranteed to return only if value has changed, even if the underlying implementation unblocks spuriously. 🫢

🚨 okay bestie, important: if order is one of std::memory_order::release and std::memory_order::acq_rel, the behavior is undefined. not cute, not safe, undefined. πŸ’€

πŸŽ€ Parameters πŸŽ€

  • old β€” the value to check the atomic_flag's object no longer contains.
  • order β€” memory order constraints to enforce.

πŸ’– Return value πŸ’–

(none) β€” literally none, bestie. πŸ™ˆ


🧚 Notes 🧚

this form of change-detection is often more efficient than simple polling or pure spinlocks. ✨

due to the ABA problem, transient changes from old to another value and back to old might be missed, and not unblock. 😭 that's the tea.


πŸ“ Example πŸ“

so the Example section is literally incomplete bestie:

This section is incomplete Reason: no example

πŸ”₯ See also πŸ”₯

  • notify_one β€” notifies at least one thread waiting on the atomic object. (C++20) (public member function)
  • notify_all β€” notifies all threads blocked waiting on the atomic object. (C++20) (public member function)
  • atomic_flag_notify_one β€” notifies a thread blocked in atomic_flag_wait. (C++20) (function)
  • atomic_flag_notify_all β€” notifies all threads blocked in atomic_flag_wait. (C++20) (function)

πŸ‘‘ Category πŸ‘‘

  • Todo no example β€” category tag: * Todo no example. slay, but also 😭.

mwah πŸ’‹ β€” this page came from http://cppreference.com, version/date 2024.06.10, and it's std::atomic_flag::wait(3). that's the footer tea, periodt. 🫢🌈

πŸ“¦ where this page comes from