Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/atomic/atomic store"

From cppreference.com
< cpp‎ | atomic
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/atomic/navbar}}
+
{{cpp/thread/navbar}}
 
{{dcl begin}}
 
{{dcl begin}}
{{dcl header | atomic }}
+
{{dcl header|atomic}}
{{dcl | num=1 | notes={{mark since c++11}} | 1=
+
{{dcl|num=1|since=c++11|
 
template< class T >
 
template< class T >
void atomic_store( std::atomic<T>* obj, T desr );
+
void atomic_store( std::atomic<T>* obj,
 +
                  typename std::atomic<T>::value_type desired ) noexcept;
 
}}
 
}}
{{dcl | num=2 | notes={{mark since c++11}} | 1=
+
{{dcl|num=2|since=c++11|
 
template< class T >
 
template< class T >
void atomic_store( volatile std::atomic<T>* obj, T desr );
+
void atomic_store( volatile std::atomic<T>* obj,
 +
                  typename std::atomic<T>::value_type desired ) noexcept;
 
}}
 
}}
{{dcl | num=3 | notes={{mark since c++11}} | 1=
+
{{dcl|num=3|since=c++11|
 
template< class T >
 
template< class T >
void atomic_store_explicit( std::atomic<T>* obj, T desr,  
+
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 | notes={{mark since c++11}} | 1=
+
{{dcl|num=4|since=c++11|
 
template< class T >
 
template< class T >
void atomic_store_explicit( volatile std::atomic<T>* obj, T desr,  
+
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-2) Atomically replaces the value pointed to by {{tt|obj}} with the value of {{tt|desr}} as if by {{c|obj->store(desr)}}
+
@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-4) Atomically replaces the value pointed to by {{tt|obj}} with the value of {{tt|desr}} as if by {{c|obj->store(desr, order)}}
+
@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 | desr | the value to store in the atomic object}}
+
{{par|desired|the value to store in the atomic object}}
{{par | order | the memory synchronization ordering for this operation: only {{lc|std::memory_order_relaxed}}, {{lc|std::memory_order_release}} and {{lc|std::memory_order_seq_cst}} are permitted.}}
+
{{par|order|the memory synchronization ordering}}
 
{{par end}}  
 
{{par end}}  
  
 
===Return value===
 
===Return value===
none.
+
(none)
  
===Exceptions===
+
===Defect reports===
{{noexcept}}
+
{{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/dcl list store | mem=std::atomic<T>}}
+
{{dsc inc|cpp/atomic/atomic/dsc store|mem=std::atomic<T>}}
{{dsc inc | cpp/atomic/dcl list atomic_load}}
+
{{dsc inc|cpp/atomic/dsc atomic_load}}
{{dsc inc | cpp/atomic/dcl list memory_order}}
+
{{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}}
  
[[de:cpp/atomic/atomic store]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/atomic/atomic store]]
+
[[fr:cpp/atomic/atomic store]]
+
[[it:cpp/atomic/atomic store]]
+
[[ja:cpp/atomic/atomic store]]
+
[[pt:cpp/atomic/atomic store]]
+
[[ru:cpp/atomic/atomic store]]
+
[[zh:cpp/atomic/atomic store]]
+

Latest revision as of 04:49, 24 April 2024

 
 
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
Safe Reclamation
(C++26)
Hazard Pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
Memory ordering
Free functions for atomic operations
atomic_storeatomic_store_explicit
(C++11)(C++11)
Free functions for atomic flags
 
Defined in header <atomic>
template< class T >

void atomic_store( std::atomic<T>* obj,

                   typename std::atomic<T>::value_type desired ) noexcept;
(1) (since C++11)
template< class T >

void atomic_store( volatile std::atomic<T>* obj,

                   typename std::atomic<T>::value_type desired ) noexcept;
(2) (since C++11)
template< class T >

void atomic_store_explicit( std::atomic<T>* obj,
                            typename std::atomic<T>::value_type desired,

                            std::memory_order order) noexcept;
(3) (since C++11)
template< class T >

void atomic_store_explicit( volatile std::atomic<T>* obj,
                            typename std::atomic<T>::value_type desired,

                            std::memory_order order) noexcept;
(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 because
T was deduced from multiple arguments
T is only deduced
from obj

[edit] See also

atomically replaces the value of the atomic object with a non-atomic argument
(public member function of std::atomic<T>) [edit]
atomically obtains the value stored in an atomic object
(function template) [edit]
defines memory ordering constraints for the given atomic operation
(enum) [edit]
specializes atomic operations for std::shared_ptr
(function template)
C documentation for atomic_store, atomic_store_explicit