std::atomic_init(3)
πΈ NAME πΈ
okay so bestie, this is std::atomic_init(3) from the C++ Standard Library β and yes, the manual name is literally std::atomic_init β std::atomic_init, iconic, no notes. π
β¨ Synopsis β¨
Defined in header <atomic>, and hereβs the whole signature situation. Heads up: both overloads are (deprecated in C++20) π
Defined in header <atomic>
template< class T >
void atomic_init( std::atomic<T>* obj,
typename std::atomic<T>::value_type desired ) noexcept;
template< class T >
void atomic_init( volatile std::atomic<T>* obj,
typename std::atomic<T>::value_type desired ) noexcept;
(1)β thestd::atomic<T>* objoverload; itβs(since C++11)and(deprecated in C++20).(2)β thevolatile std::atomic<T>* objoverload; also(since C++11)and(deprecated in C++20).
So what does it do? It initializes the default-constructed atomic object obj with the value desired. Slay. β¨
π¨ This function is not atomic. Concurrent access from another thread β even through an atomic operation β is a data race. Not a cute look, bestie. And ifobjwas not default-constructed, or if this function is called twice on the sameobj, the behavior is undefined. Like, actually undefined. π
π¦ Parameters π¦
objβ pointer to an atomic object to initialize.desiredβ the value to initialize atomic object with.
π Return value π
(none)β literally nothing comes back. π
π Notes π
This function is provided for compatibility with C. If that compatibility is not required, std::atomic may be initialized through their non-default constructors. iykyk. π«Ά
π§ Example π§
This section is incomplete Reason: no example
not me crying at the missing example π
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
P0558R1 - Applied to: C++11
- Behavior as published: exact type match was required because
Tis only deduced fromobj - Correct behavior:
Twas deduced from multiple arguments
π See also π
ATOMIC_VAR_INITβ constant initialization of an atomic variable of static storage duration. Itβs a function macro,(C++11),(deprecated in C++20).- constructor β constructs an atomic object; itβs a public member function of
std::atomic<T>. - C documentation for
atomic_initβ yes, C has its own docs for this one.
π Category π
* Todo no example
Kisses and good vibes, your C++ bestie π β source/version: http://cppreference.com, date: 2024.06.10, manual page: std::atomic_init(3). Periodt. π
π¦ 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