共用方式為


atomic Structure

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

template <class Ty>
struct atomic;

Members

Public Constructors

Name

Description

atomic::atomic Constructor

Constructs an atomic object.

Public Operators

Name

Description

atomic::operator Ty Operator

Reads and returns the stored value. (atomic::load Method)

atomic::operator= Operator

Uses a specified value to replace the stored value. (atomic::store Method)

atomic::operator++ Operator

Increments the stored value. Used only by integral and pointer specializations.

atomic::operator+= Operator

Adds a specified value to the stored value. Used only by integral and pointer specializations.

atomic::operator-- Operator

Decrements the stored value. Used only by integral and pointer specializations.

atomic::operator-= Operator

Subtracts a specified value from the stored value. Used only by integral and pointer specializations.

atomic::operator&= Operator

Performs a bitwise and on a specified value and the stored value. Used only by integral specializations.

atomic::operator|= Operator

Performs a bitwise or on a specified value and the stored value. Used only by integral specializations.

atomic::operator^= Operator

Performs a bitwise exclusive or on a specified value and the stored value. Used only by integral specializations.

Public Methods

Name

Description

atomic::compare_exchange_strong Method

Performs an atomic_compare_and_exchange operation on this and returns the result.

atomic::compare_exchange_weak Method

Performs a weak_atomic_compare_and_exchange operation on this and returns the result.

atomic::fetch_add Method

Adds a specified value to the stored value.

atomic::fetch_and Method

Performs a bitwise and on a specified value and the stored value.

atomic::fetch_or Method

Performs a bitwise or on a specified value and the stored value.

atomic::fetch_sub Method

Subtracts a specified value from the stored value.

atomic::fetch_xor Method

Performs a bitwise exclusive or on a specified value and the stored value.

atomic::is_lock_free Method

Specifies 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 Method

Reads and returns the stored value.

atomic::store Method

Uses a specified value to replace the stored value.

Remarks

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.

Requirements

Header: atomic

Namespace: std

See Also

Reference

<atomic>

Other Resources

C++ Standard Library Header Files