std::atomic_ref::wait(3)
π NAME π
Okay bestie, welcome to std::atomic_ref::wait β literally std::atomic_ref::wait β from the C++ Standard Libary (that spelling is the header's, not mine π). This is the manual page for atomic waiting, and it's giving patient-icon energy. β¨
π Synopsis π
void wait( T old, std::memory_order order =
std::memory_order::seq_cst ) const noexcept;
(1) (since C++20)
void wait( T old, std::memory_order order =
std::memory_order::seq_cst ) const volatile
noexcept;
(2) (since C++20)
Performs atomic waiting operations. Behaves as if it repeatedly performs the following steps:
- Compare the value representation of
this->load(order)with that ofold.- If those are equal, then blocks until
*thisis notified bynotify_one()ornotify_all(), or the thread is unblocked spuriously. - Otherwise, returns.
- If those are equal, then blocks until
These functions are guaranteed to return only if value has changed, even if underlying implementation unblocks spuriously. π«Ά
π¨ Iforderis one ofstd::memory_order::releaseandstd::memory_order::acq_rel, the behavior is undefined. Do not do that, bestie β that's not the vibe.
π Parameters π
oldβ the value to check theatomic_ref's object no longer containsorderβ memory order constraints to enforce
πΈ Return value πΈ
(none) β she returns nothing. Iconic minimalism. π
π¦ Notes π¦
This form of change-detection is often more efficient than simple polling or pure spinlocks. Slay.
Due to the ABA problem, transient changes from old to another value and back to old might be missed, and not unblock. π The classic "you changed but also changed back" betrayal.
The comparison is bitwise (similar to std::memcmp); no comparison operator is used. Padding bits that never participate in an object's value representation are ignored. Fr fr, bitwise.
π Example π
This section is incomplete Reason: no example
π See also π
notify_oneβ notifies at least one thread waiting on the atomic object (public member function)notify_allβ notifies all threads blocked waiting on the atomic object (public member function)atomic_notify_one(C++20) β notifies a thread blocked inatomic_wait(function template)atomic_notify_all(C++20) β notifies all threads blocked inatomic_wait(function template)
π Category π
Todo no example
That's the whole page, bestie β source is http://cppreference.com, version/date 2024.06.10, and the page is std::atomic_ref::wait(3). Catch you in the group chat, mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms