Search code examples
c++shared-ptrlock-free

Is shared_ptr<void>::reset() lock-free?


Imagine the following:

// SECTION A
MyClass* object = new MyClass();
std::shared_ptr<void> sharedObject;

// SECTION B (sharedObject is empty)
sharedObject.reset(object);

Is section B lock-free for an empty sharedObject? Or does it depend of the implementation?


Solution

  • This depends on implementation.

    Some pointers:

    1. Overhead and implementation of using shared_ptr
    2. Linking pthread disables lock-free shared_ptr implementation