std::atomic_notify_all(3)

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

πŸ’… std::atomic_notify_all β€” from the C++ Standard Library

okay so bestie, welcome to std::atomic_notify_all πŸ’– this whole page lives in the C++ Standard Library, and we're about to make waking up threads sound as cute as it actually is (it's lowkey iconic, fr).


✨ NAME ✨

std::atomic_notify_all β€” like, literally std::atomic_notify_all. that's the name. that's the vibe. πŸŽ€


🌸 SYNOPSIS 🌸

so it's defined in the header <atomic>, and there are two flavors of this bad boy β€” both since C++20, no cap:

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

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

what does it actually do? it performs atomic notifying operations. that's the whole job. πŸ’…

here's the tea: it unblocks all threads that are blocked in atomic waiting operations β€” and to be clear, that means std::atomic_wait(), std::atomic_wait_explicit(), or std::atomic::wait() β€” on *object, if there are any threads chillin' there. if there aren't any? it just does nothing. literally nothing. it's fine, it's giving unbothered. πŸ¦‹

and hey, it's equivalent to object->notify_all(). same energy, different outfit. ✨


🧚 PARAMETERS 🧚

  • object β€” pointer to the atomic object to notify. that's the one getting the group-chat ping. 🫢

πŸ’€ RETURN VALUE πŸ’€

(none) β€” nothing. zero. nada. it doesn't return anything, it just does the thing. πŸ™ˆ


πŸ‘‘ NOTES πŸ‘‘

ngl, this form of change-detection is often more efficient than simple polling or pure spinlocks. so like… stop spinlocking, bestie. it's not the moment. πŸ”₯


🌈 EXAMPLE 🌈

This section is incomplete Reason: no example

(yeah 😭 no example yet. we're waiting on it. main character energy but the chapter hasn't dropped. ⭐)


πŸ“ 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_wait, atomic_wait_explicit β€” blocks the thread until notified and the atomic value changes β€” (C++20) (function template)
  • atomic_notify_one β€” notifies a thread blocked in atomic_wait β€” (C++20) (function template)

πŸŽ€ CATEGORY πŸŽ€

  • Todo no example

okay that's the whole page, you ate that πŸ§šπŸ’œ

and now the cute little sign-off: this one's from cppreference.com, version 2024.06.10, filed under std::atomic_notify_all(3) β€” screenshot it, memorize it, live it, periodt. πŸŒΈπŸ’…πŸ¦‹

πŸ“¦ where this page comes from