STD::ATOMIC(3)
π std::atomic< _Tp > β the generic atomic type, primary class template π
okay bestie so this is std::atomic< _Tp >(3), straight outta the Library Functions Manual, and it's genuinely one of the most iconic glow-ups in the whole C++ standard library. no cap. if you've ever had two threads fighting over the same variable like it's the last matcha in the fridge, this is the class template that ends the drama. π«Ά
β¨ NAME β¨
std::atomic< _Tp > β Generic atomic type, primary class template. that's the whole vibe. it's the primary one, the blueprint, the main character π
π SYNOPSIS π
#include <atomic>
π Public Types
using value_typeβ yeah it's just chillin' there, one type, doing its thing.
π¦ Public Member Functions
okay this list is LONG and I am NOT skipping a single one, because every overload here is a baddie and they all earned their spot π
constexpr atomic (_Tp __i) noexceptβ build one of these, feed it your starting value__i, no exceptions, we don't do that here.atomic (const atomic &)=deleteβ nope. copying is deleted. atoms don't get duplicated, that's the whole point, periodt. πbool compare_exchange_strong (_Tp &__e, _Tp __i, memory_order __m=memory_order_seq_cst) noexceptβ the strong compare-and-swap. if the current value matches__e, swap in__iand saytrue; otherwise write the actual value back into__eand sayfalse. default orderingmemory_order_seq_cst.bool compare_exchange_strong (_Tp &__e, _Tp __i, memory_order __m=memory_order_seq_cst) volatile noexceptβ same energy, butvolatile.bool compare_exchange_strong (_Tp &__e, _Tp __i, memory_order __s, memory_order __f) noexceptβ strong version where you get to pick two orderings:__sfor success,__ffor failure. so flexible β¨bool compare_exchange_strong (_Tp &__e, _Tp __i, memory_order __s, memory_order __f) volatile noexceptβ thevolatiletwin of the above.bool compare_exchange_weak (_Tp &__e, _Tp __i, memory_order __m=memory_order_seq_cst) noexceptβ the weak one. same deal, same default ordering, but it's allowed to fail even when the values match (spurious failure is real, that's just how it is on some hardware).bool compare_exchange_weak (_Tp &__e, _Tp __i, memory_order __m=memory_order_seq_cst) volatile noexceptβ weak,volatile, iconic.bool compare_exchange_weak (_Tp &__e, _Tp __i, memory_order __s, memory_order __f) noexceptβ weak + your choice of success ordering__sand failure ordering__f.bool compare_exchange_weak (_Tp &__e, _Tp __i, memory_order __s, memory_order __f) volatile noexceptβ and thevolatileversion of that one too. we contain multitudes._Tp exchange (_Tp __i, memory_order __m=memory_order_seq_cst) noexceptβ drop in__iand hand back the old value. give and receive, that's the exchange. π_Tp exchange (_Tp __i, memory_order __m=memory_order_seq_cst) volatile noexceptβ exchange, butvolatile.bool is_lock_free () const noexceptβ asks the question we all ask: is this thing actually lock-free, or is it secretly locking under the hood?const, no exceptions.bool is_lock_free () const volatile noexceptβ same question,const volatileflavour._Tp load (memory_order __m=memory_order_seq_cst) const noexceptβ read the value out. default orderingmemory_order_seq_cst,const,noexcept. π_Tp load (memory_order __m=memory_order_seq_cst) const volatile noexceptβ load, butconst volatile.operator _Tp () const noexceptβ surprise! it implicitly converts to_Tp, so you can just use it like a regular value. the versatility πoperator _Tp () const volatile noexceptβ theconst volatileconversion operator, obviously._Tp operator= (_Tp __i) noexceptβ assign a plain_Tpinto it, get the value back.noexcept, as always._Tp operator= (_Tp __i) volatile noexceptβ thevolatileassignment.atomic & operator= (const atomic &) volatile =deleteβ copy-assignment? deleted.volatileflavour. NO copying, bestie, I said what I said.atomic & operator= (const atomic &)=deleteβ and the non-volatileone is deleted too. both doors locked πvoid store (_Tp __i, memory_order __m=memory_order_seq_cst) noexceptβ write__iin. default orderingmemory_order_seq_cst, returns nothing, throws nothing. clean.void store (_Tp __i, memory_order __m=memory_order_seq_cst) volatile noexceptβ store,volatileedition.
π Detailed Description π
template<typename _Tp>
struct std::atomic< _Tp >
"Generic atomic type, primary class template."
that's the official blurb and honestly? it ate. this is the primary class template, the one all the specializations look up to.
πΈ Template Parameters
_Tpβ Type to be made atomic, must be trivially copyable. lowkey the most important sentence on this page. if your type isn't trivially copyable, this template is NOT the one for you, and it will let you know. π
π Author
Generated automatically by Doxygen for libstdc++ from the source code. no human author to thank here, just the machine doing its little automated thing. π€β¨
and that's the page, bestie!! π this one came to you from libstdc++, filed under std::atomic< _Tp >(3) β so next time you're in the terminal and you see that section-3 header, you'll know exactly who you're dealing with. go forth and atomically. π
π¦β
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms