In the boost::shared_ptr destructor, this is done:
if(--*pn == 0) { boost::checked_delete(px); delete pn; }
where pn is a pointer to a reference counter, which is typed as
shared_ptr::count_type -> detail::atomic_count -> long
I would expect long be volatile long , given the use of threads and the non-atomic 0-check-and-deletion in the shared_ptr destructor above. Why is he not changeable?
EDIT:
Turns out I looked at the header used when multi-threaded usage is not specified (atomic_count.hpp). In atomic_count_win32.hpp, the decrement is correctly implemented for multi-threaded use.
c ++ multithreading boost shared-ptr
Johann Gerell
source share