libc++ shared_ptr implementation release()
for the sake of simplicity can be depicted as:
void release()
{
if (ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1)
{
delete this;
}
}
Why doesn't libc++ split it into release decrement and acquire fence?
void release()
{
if (ref_count.fetch_sub(1, std::memory_order_release) == 1)
{
std::atomic_thread_fence(std::memory_order_acquire);
delete this;
}
}
as Boost recommends, which looks superior as it doesn't impose acquire mem order for all but the last decrement.