atomic Structure

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at atomic Structure.

Describes an object that performs atomic operations on a stored value of type Ty.

template <class Ty>
struct atomic;

Public Constructors

NameDescription
atomic::atomic ConstructorConstructs an atomic object.

Public Operators

NameDescription
atomic::operator Ty OperatorReads and returns the stored value. (atomic::load Method)
atomic::operator= OperatorUses a specified value to replace the stored value. (atomic::store Method)
atomic::operator++ OperatorIncrements the stored value. Used only by integral and pointer specializations.
atomic::operator+= OperatorAdds a specified value to the stored value. Used only by integral and pointer specializations.
atomic::operator-- OperatorDecrements the stored value. Used only by integral and pointer specializations.
atomic::operator-= OperatorSubtracts a specified value from the stored value. Used only by integral and pointer specializations.
atomic::operator&= OperatorPerforms a bitwise and on a specified value and the stored value. Used only by integral specializations.
atomic::operator|= OperatorPerforms a bitwise or on a specified value and the stored value. Used only by integral specializations.
atomic::operator^= OperatorPerforms a bitwise exclusive or on a specified value and the stored value. Used only by integral specializations.

Public Methods

NameDescription
atomic::compare_exchange_strong MethodPerforms an atomic_compare_and_exchange operation on this and returns the result.
atomic::compare_exchange_weak MethodPerforms a weak_atomic_compare_and_exchange operation on this and returns the result.
atomic::fetch_add MethodAdds a specified value to the stored value.
atomic::fetch_and MethodPerforms a bitwise and on a specified value and the stored value.
atomic::fetch_or MethodPerforms a bitwise or on a specified value and the stored value.
atomic::fetch_sub MethodSubtracts a specified value from the stored value.
atomic::fetch_xor MethodPerforms a bitwise exclusive or on a specified value and the stored value.
atomic::is_lock_free MethodSpecifies whether atomic operations on this are lock free. An atomic type is lock free if no atomic operations on that type use locks.
atomic::load MethodReads and returns the stored value.
atomic::store MethodUses a specified value to replace the stored value.

The type Ty must be trivially copyable. That is, using memcpy to copy its bytes must produce a valid Ty object that compares equal to the original object. The compare_exchange_weak and compare_exchange_strong member functions use memcmp to determine whether two Ty values are equal. These functions will not use a Ty-defined operator==. The member functions of atomic use memcpy to copy values of type Ty.

A partial specialization, atomic<Ty *>, exists for all pointer types. The specialization enables the addition of an offset to the managed pointer value or the subtraction of an offset from it. The arithmetic operations take an argument of type ptrdiff_t and adjust that argument according to the size of Ty to be consistent with ordinary address arithmetic.

A specialization exists for every integral type except bool. Each specialization provides a rich set of methods for atomic arithmetic and logical operations.

atomic<char>atomic<signed char>atomic<unsigned char>
atomic<char16_t>atomic<char32_t>atomic<wchar_t>
atomic<short>atomic<unsigned short>atomic<int>
atomic<unsigned int>atomic<long>atomic<unsigned long>
atomic<long long>atomic<unsigned long long>

Integral specializations are derived from corresponding atomic_``integral types. For example, atomic<unsigned int> is derived from atomic_uint.

Header: atomic

Namespace: std

<atomic>
Header Files Reference

Show: