C++ Logo

std-proposals

Advanced search

[std-proposals] Improvement for std::shared_ptr<T>

From: Oliver Schädlich <oliver.schaedlich_at_[hidden]>
Date: Sun, 25 Aug 2024 17:22:20 +0200

If you assign a atomic<shared_ptr<T>> to a shared_ptr<T> a complex copy-process takes place.
A lock-free implementation is possible, but this includes a row of atomic operations and thereby
expensive cacheline-invalidation in other CPU's caches.
So if you have a RCU-like pattern where the shared atomic<shared_ptr<T>> is rarely updated
copying is rather expensive. So there could be an overload of the assinment-operator of
shared_ptr<T> which internally first shoud compare its own pointer against the pointer of
the atomic<shared_ptr<T>> and if they're the same simply do nothing. If the participating
threads would keep a thread_local copy of the atomic<shared_ptr<T>> RCU-like patterns
would become more efficient than with userspace-RCU.

Received on 2024-08-25 15:22:23