This is a bit of a two part question, all about the atomicity of std::shared_ptr
:
1.
As far as I can tell, std::shared_ptr
is the only smart pointer in <memory>
that's atomic. I'm wondering if there is a non-atomic version of std::shared_ptr
available (I can't see anything in <memory>
, so I'm also open to suggestions outside of the standard, like those in Boost). I know boost::shared_ptr
is also atomic (if BOOST_SP_DISABLE_THREADS
isn't defined), but maybe there's another alternative? I'm looking for something that has the same semantics as std::shared_ptr
, but without the atomicity.
2. I understand why std::shared_ptr
is atomic; it's kinda nice. However, it's not nice for every situation, and C++ has historically had the mantra of "only pay for what you use." If I'm not using multiple threads, or if I am using multiple threads but am not sharing pointer ownership across threads, an atomic smart pointer is overkill. My second question is why wasn't a non-atomic version of std::shared_ptr
provided in C++11? (assuming there is a why) (if the answer is simply "a non-atomic version was simply never considered" or "no one ever asked for a non-atomic version" that's fine!).
With question #2, I'm wondering if someone ever proposed a non-atomic version of shared_ptr
(either to Boost or the standards committee) (not to replace the atomic version of shared_ptr
, but to coexist with it) and it was shot down for a specific reason.