atomic_fetch_sub Function

Subtracts a value from an existing value that is stored in an atomic object.

template <class T> T* atomic_fetch_sub(
   volatile atomic<T*> *Atom,
   ptrdiff_t Value
) noexcept;

template <class T> T* atomic_fetch_sub(
   atomic<T*> *Atom,
   ptrdiff_t Value
) noexcept;

Parameters

  • Atom
    A pointer to an atomic object that stores a pointer to type T.

  • Value
    A value of type ptrdiff_t.

Return Value

The value of the pointer contained by the atomic object immediately before the operation was performed.

Remarks

The atomic_fetch_sub function performs a read-modify-write operation to atomically subtract Value from the stored value in Atom, using the memory_order_seq_cstmemory_order constraint.

When the atomic type is atomic_address, Value has type ptrdiff_t and the operation treats the stored pointer as a char *.

This operation is also overloaded for integral types:

integral atomic_fetch_sub(
    volatile atomic-integral * Atom, integral Value
) noexcept;

integral atomic_fetch_sub(
    atomic-integral * Atom, integral Value
) noexcept;

Requirements

Header: atomic

Namespace: std

See Also

Reference

<atomic>

atomic Structure

atomic_fetch_sub_explicit Function