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

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

Instances of std::experimental::atomic_weak_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_weak_ptr
{
    constexpr atomic_weak_ptr() noexcept = default;
    atomic_weak_ptr(weak_ptr<T>) noexcept;
    weak_ptr<T> operator=(weak_ptr<T>) noexcept;

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

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

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

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

#include <experimental/atomic>

See Also