Difference between revisions of "cpp/atomic/atomic store"
From cppreference.com
m (Shorten template names. Use {{lc}} where appropriate.) |
(Applied P2869R4 (Remove Deprecated shared_ptr Atomic Access APIs from C++26).) |
||
(17 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
{{cpp/title|atomic_store|atomic_store_explicit}} | {{cpp/title|atomic_store|atomic_store_explicit}} | ||
− | {{cpp/ | + | {{cpp/thread/navbar}} |
{{dcl begin}} | {{dcl begin}} | ||
− | {{dcl header | atomic }} | + | {{dcl header|atomic}} |
− | {{dcl | num=1 | | + | {{dcl|num=1|since=c++11| |
template< class T > | template< class T > | ||
− | void atomic_store( std::atomic<T>* obj, T | + | void atomic_store( std::atomic<T>* obj, |
+ | typename std::atomic<T>::value_type desired ) noexcept; | ||
}} | }} | ||
− | {{dcl | num=2 | | + | {{dcl|num=2|since=c++11| |
template< class T > | template< class T > | ||
− | void atomic_store( volatile std::atomic<T>* obj, T | + | void atomic_store( volatile std::atomic<T>* obj, |
+ | typename std::atomic<T>::value_type desired ) noexcept; | ||
}} | }} | ||
− | {{dcl | num=3 | | + | {{dcl|num=3|since=c++11| |
template< class T > | template< class T > | ||
− | void atomic_store_explicit( std::atomic<T>* obj, T | + | void atomic_store_explicit( std::atomic<T>* obj, |
− | std::memory_order order); | + | typename std::atomic<T>::value_type desired, |
+ | std::memory_order order) noexcept; | ||
}} | }} | ||
− | {{dcl | num=4 | | + | {{dcl|num=4|since=c++11| |
template< class T > | template< class T > | ||
− | void atomic_store_explicit( volatile std::atomic<T>* obj, T | + | void atomic_store_explicit( volatile std::atomic<T>* obj, |
− | std::memory_order order); | + | typename std::atomic<T>::value_type desired, |
+ | std::memory_order order) noexcept; | ||
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
− | 1 | + | @1,2@ Atomically replaces the value pointed to by {{c|obj}} with the value of {{c|desired}} as if by {{c|obj->store(desired)}}. |
− | 3 | + | @3,4@ Atomically replaces the value pointed to by {{c|obj}} with the value of {{c|desired}} as if by {{c|obj->store(desired, order)}}. |
+ | @@ If {{c|order}} is one of {{c|std::memory_order_consume}}, {{c|std::memory_order_acquire}} and {{c|std::memory_order_acq_rel}}, the behavior is undefined. | ||
===Parameters=== | ===Parameters=== | ||
− | |||
{{par begin}} | {{par begin}} | ||
− | {{par | obj | pointer to the atomic object to modify}} | + | {{par|obj|pointer to the atomic object to modify}} |
− | {{par | | + | {{par|desired|the value to store in the atomic object}} |
− | {{par | order | the memory synchronization ordering | + | {{par|order|the memory synchronization ordering}} |
{{par end}} | {{par end}} | ||
===Return value=== | ===Return value=== | ||
− | none | + | (none) |
− | === | + | ===Defect reports=== |
− | {{ | + | {{dr list begin}} |
+ | {{dr list item|std=C++11|paper=P0558R1|before=exact type match was required because<br>{{tt|T}} was deduced from multiple arguments|after={{tt|T}} is only deduced<br>from {{c|obj}}}} | ||
+ | {{dr list end}} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/atomic/atomic/ | + | {{dsc inc|cpp/atomic/atomic/dsc store|mem=std::atomic<T>}} |
− | {{dsc inc | cpp/atomic/ | + | {{dsc inc|cpp/atomic/dsc atomic_load}} |
− | {{dsc inc | cpp/atomic/ | + | {{dsc inc|cpp/atomic/dsc memory_order}} |
− | {{dsc tfun | cpp/memory/shared_ptr/atomic | title=std::atomic_store{{dsc small|(std::shared_ptr)}} | + | {{dsc break}} |
− | <br>std::atomic_store_explicit{{dsc small|(std::shared_ptr)}} | specializes atomic operations for {{lc|std::shared_ptr}} }} | + | {{dsc tfun|cpp/memory/shared_ptr/atomic|notes={{mark life|deprecated=c++20|removed=c++26|br=yes}}|title=std::atomic_store{{dsc small|(std::shared_ptr)}} |
− | {{dsc see c | c/atomic/atomic_store | atomic_store | atomic_store_explicit}} | + | <br>std::atomic_store_explicit{{dsc small|(std::shared_ptr)}}|specializes atomic operations for {{lc|std::shared_ptr}}}} |
+ | {{dsc see c|c/atomic/atomic_store|atomic_store|atomic_store_explicit}} | ||
{{dsc end}} | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 04:49, 24 April 2024
Defined in header <atomic>
|
||
template< class T > void atomic_store( std::atomic<T>* obj, |
(1) | (since C++11) |
template< class T > void atomic_store( volatile std::atomic<T>* obj, |
(2) | (since C++11) |
template< class T > void atomic_store_explicit( std::atomic<T>* obj, |
(3) | (since C++11) |
template< class T > void atomic_store_explicit( volatile std::atomic<T>* obj, |
(4) | (since C++11) |
1,2) Atomically replaces the value pointed to by obj with the value of desired as if by obj->store(desired).
3,4) Atomically replaces the value pointed to by obj with the value of desired as if by obj->store(desired, order).
If order is one of std::memory_order_consume, std::memory_order_acquire and std::memory_order_acq_rel, the behavior is undefined.
Contents |
[edit] Parameters
obj | - | pointer to the atomic object to modify |
desired | - | the value to store in the atomic object |
order | - | the memory synchronization ordering |
[edit] Return value
(none)
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
P0558R1 | C++11 | exact type match was required becauseT was deduced from multiple arguments
|
T is only deducedfrom obj |
[edit] See also
atomically replaces the value of the atomic object with a non-atomic argument (public member function of std::atomic<T> )
| |
(C++11)(C++11) |
atomically obtains the value stored in an atomic object (function template) |
(C++11) |
defines memory ordering constraints for the given atomic operation (enum) |
(deprecated in C++20)(removed in C++26) |
specializes atomic operations for std::shared_ptr (function template) |
C documentation for atomic_store, atomic_store_explicit
|