Documentation Home >> Headers >> <experimental/atomic> Header

The <experimental/atomic> header contains the atomic_shared_ptr and atomic_weak_ptr class templates from the Concurrency TS. These provide atomic objects for storing shared_ptr and weak_ptr instances.

This requires integration with std::shared_ptr and std::weak_ptr, so just::thread provides additional implementations of these class templates in the std::experimental namespace. std::experimental::shared_ptr can be used as a drop-in replacement for std::shared_ptr, and instances can be freely converted back and forth, though this will incur the cost of memory allocation for the reference tracking of the "other" type when converting.

std::experimental::atomic_shared_ptr<int> ap;
std::shared_ptr<int> sp(std::make_shared<int>(42));
std::experimental::shared_ptr<int> sp2=sp; // allocates
ap.store(sp2); // no allocation

namespace std
{
    namespace experimental
    {
            template<typename T>
            class shared_ptr;
            template<typename T>
            class weak_ptr;
            template<typename T>
            class enable_shared_from_this;

            template<typename T>
            class atomic_shared_ptr;
            template<typename T>
            class atomic_weak_ptr;
    }
}
See Also