CKTIS / C++
Atomic shared_ptr stores and loads through free functions
The std::shared_ptr overloads of std::atomic_store_explicit and std::atomic_load_explicit atomically replace and retrieve a shared handle. Deprecated in C++23, they protect the handle and ownership, not arbitrary operations on the pointed-to object.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <memory>
#include <atomic>
template<class T>
void atomic_store_explicit(std::shared_ptr<T>* p,
std::shared_ptr<T> desired,
std::memory_order order);
template<class T>
std::shared_ptr<T> atomic_load_explicit(const std::shared_ptr<T>* p,
std::memory_order order);
// Both function templates belong to namespace std.In C++23, these functions from <memory> operate on an ordinary std::shared_ptr<T> object, not a std::atomic<T>. std::atomic_store_explicit(std::shared_ptr<T>*, ...) atomically replaces the handle with desired and returns void. std::atomic_load_explicit(const std::shared_ptr<T>*, ...) atomically returns a handle copy that retains shared ownership. The pointer p must designate a live object; a load can return an empty handle.
The order parameter selects memory ordering. Stores allow std::memory_order_relaxed, std::memory_order_release, and std::memory_order_seq_cst. Loads in C++23 allow std::memory_order_relaxed, std::memory_order_consume, std::memory_order_acquire, and std::memory_order_seq_cst. Other orders cause undefined behavior. An acquire load that reads the value published by a release store makes earlier initialization visible; relaxed alone does not provide that synchronization.
Do not mix these operations with ordinary assignment, reset(), or copying of the same handle when access can overlap a write: that risks a data race. Atomicity of the handle does not protect modifications to *snapshot; those require separate synchronization. Do not assume lock-free operation either. Keep the slot object alive throughout all access.
This is a legacy interface, deprecated since C++20 and removed in C++26. The supplied section's current address only reports removal; it is not a C++23 snapshot. Its replacement is std::atomic<std::shared_ptr<T>> with store() and load() members, which express atomic access in the type. This entry targets C++23; the repository compiler flag does not attest a production runtime.
Examples
#include <atomic>
#include <iostream>
#include <memory>
int main() {
std::shared_ptr<const int> slot;
std::shared_ptr<const int> value = std::make_shared<const int>(42);
std::atomic_store_explicit(&slot, value, std::memory_order_release);
auto snapshot = std::atomic_load_explicit(&slot, std::memory_order_acquire);
std::cout << *snapshot << '\n';
}
Result
42
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.