std::atomic_notify_one(3)

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

πŸŽ€ NAME πŸŽ€

okay so this is std::atomic_notify_one(3) from the C++ Standard Libary manual β€” yes, that’s the manual name, typo and all, we’re keeping it πŸ’…. The NAME is std::atomic_notify_one - std::atomic_notify_one (the name said β€œI’m my own twin,” iconic).

✨ Synopsis ✨

Defined in header <atomic>, and it’s giving two overloads, both since C++20:

template< class T >                                        (1) (since C++20)
void atomic_notify_one( std::atomic<T>* object );
template< class T >                                        (2) (since C++20)
void atomic_notify_one( volatile std::atomic<T>* object );

It performs atomic notifying operations. If there is a thread blocked in atomic waiting operation β€” that’s std::atomic_wait(), std::atomic_wait_explicit(), or std::atomic::wait() β€” on *object, then it unblocks at least one such thread; otherwise it does nothing. It’s equivalent to object->notify_one(). Slay.

🧚 Parameters 🧚

  • object β€” pointer to the atomic object to notify. That’s the one getting the little wake-up tap πŸ’–.

πŸ’« Return value πŸ’«

(none) β€” it literally returns nothing, bestie, periodt. It’s too busy being a notifier.

🌸 Notes 🌸

ngl, this form of change-detection is often more efficient than simple polling or pure spinlocks. Lowkey a glow-up over sitting there spinning or polling like a lost cause.

πŸ’€ Example πŸ’€

This section is incomplete Reason: no example

That’s the whole example section, no cap, fr fr. It’s giving placeholder era, and we respect it 🫑.

🌈 See also 🌈

  • notify_one β€” notifies at least one thread waiting on the atomic object; (C++20); public member function of std::atomic<T>.
  • notify_all β€” notifies all threads blocked waiting on the atomic object; (C++20); public member function of std::atomic<T>.
  • atomic_notify_all β€” notifies all threads blocked in atomic_wait; (C++20); function template.
  • atomic_wait β€” (C++20).
  • atomic_wait_explicit β€” blocks the thread until notified and the atomic value changes; (C++20); function template.
  • Also keeping the spare (C++20) that’s chillin’ at the end of the source list: (C++20).

🌟 Category 🌟

  • Todo no example

Source/version: http://cppreference.com β€” dated 2024.06.10 β€” page std::atomic_notify_one(3). Stay atomic, bestie πŸ«ΆπŸ’–

πŸ“¦ where this page comes from