Documentation Home >> Headers >> <jss/experimental_atomic.hpp> Header >> std::experimental::atomic_shared_ptr class template

Instances of the atomic_shared_ptr class template provide atomic access to the contained std::experimental::shared_ptr instance. The interface is similar to that of the std::atomic class template for POD structs.

atomic_shared_ptr instances count as std::experimental::shared_ptr instances for calls to the use_count member function on objects that share ownership with the value stored in the atomic_shared_ptr instances.

Instances of std::experimental::atomic_shared_ptr are lock-free if the target CPU supports double-word-compare-and-swap. This is true for all supported 32-bit CPUs, and for 64-bit CPUs that support the CMPXCHG16B instruction. This determination is done at runtime, since it depends on the model of the CPU rather than the OS or compiler.

template<typename T>
struct atomic_shared_ptr
{
    constexpr atomic_shared_ptr() noexcept = default;
    atomic_shared_ptr(shared_ptr<T>) noexcept;
    shared_ptr<T> operator=(shared_ptr<T>) noexcept;

    atomic(const atomic&) = delete;
    atomic& operator=(const atomic&) = delete;

    bool is_lock_free() const noexcept;
    void store(
        shared_ptr<T>,
        memory_order = memory_order_seq_cst) noexcept;
    shared_ptr<T> load(
        memory_order = memory_order_seq_cst)
        const noexcept;
    shared_ptr<T> exchange(
        shared_ptr<T>,memory_order = memory_order_seq_cst)
        noexcept

    bool compare_exchange_strong(
        shared_ptr<T> & old_value, shared_ptr<T> new_value,
        memory_order order = memory_order_seq_cst)
        noexcept;
    bool compare_exchange_strong(
        shared_ptr<T> & old_value, shared_ptr<T> new_value,
        memory_order success_order,
        memory_order failure_order) noexcept;
    bool compare_exchange_weak(
        shared_ptr<T> & old_value, shared_ptr<T> new_value,
        memory_order order = memory_order_seq_cst)
        noexcept;
    bool compare_exchange_weak(
        shared_ptr<T> & old_value, shared_ptr<T> new_value,
        memory_order success_order,
        memory_order failure_order) noexcept;

    operator shared_ptr<T> () const noexcept;
};
Header

#include <experimental/atomic>

See Also