Why isn't the reference counter in boost::shared_ptr volatile?

Posted by Johann Gerell on Stack Overflow See other posts from Stack Overflow or by Johann Gerell
Published on 2010-03-26T11:02:27Z Indexed on 2010/03/26 11:03 UTC
Read the original article Hit count: 478

Filed under:
|
|
|

In the boost::shared_ptr destructor, this is done:

if(--*pn == 0)
{
    boost::checked_delete(px);
    delete pn;
}

where pn is a pointer to the reference counter, which is typedefed as

shared_ptr::count_type -> detail::atomic_count -> long

I would have expected the long to be volatile long, given threaded usage and the non-atomic 0-check-and-deletion in the shared_ptr destructor above. Why isn't it volatile?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost