atomic_atomic_store
atomic_atomic_store (원자적 쓰기)
std::atomic_store는 원자적 객체에 값을 원자적으로 저장해요.
출처: cppreference
본문
std::atomic_store와 std::atomic_store_explicit은 <atomic> 헤더에 정의된 자유 함수예요.
template< class T >
void atomic_store( std::atomic<T>* obj,
typename std::atomic<T>::value_type desired ) noexcept;
template< class T >
void atomic_store_explicit( std::atomic<T>* obj,
typename std::atomic<T>::value_type desired,
std::memory_order order ) noexcept;
**atomic_store**는 obj->store(desired)처럼, **atomic_store_explicit**는 obj->store(desired, order)처럼 동작해요. 객체의 값을 desired로 원자적으로 저장해요.
예제 (Example)
#include <atomic>
std::atomic<int> a{0};
int main()
{
std::atomic_store(&a, 10); // a의 값을 10으로 설정
std::atomic_store_explicit(&a, 20, std::memory_order_release);
}