Search code examples
c++shared-ptratomic

How to atomically reset a shared_ptr?


We have atomic access to shared_ptrs but I cannot see how to atomically reset them: what am I missing?


Solution

  • You can just use atomic_exchange with a default constructed shared_ptr:

    atomic_exchange(&ptr, {});