Atomically share(without a mutex) boost::intrusive_ptr?

I know boost has atomic_shared_ptr which can be used with a shared_ptr.

But is there a way to do something similar with boost::intrusive_ptr ?

i.e. is it possible to share boost::intrusive_ptr across one writer/multiple reader threads WITHOUT using mutexes ?

Back ground :

Unfortunately, my workplace allows only till C++11 (does NOT allow using C++20 yet). std::atomic_store functions in C++11 seems NOT efficient as they use mutexes under the hood(see Notes in mentioned link).

Also due to performance requirements new/delete happening in std/boost shared_ptr for Control Blocks is NOT preferred. Hence the need to use boost::intrusive_ptr.

Answer

It seems this is impossible (at least with C++11) as even boost::atomic_shared_ptr seems to use a boost::detail::spinlock for this.
ref : https://github.com/BeamMW/boost-linux/blob/master/boost/smart_ptr/atomic_shared_ptr.hpp

Leave a Reply

Your email address will not be published. Required fields are marked *