In the example of boost::atomic
, the unref
function:
void intrusive_ptr_release(const X * x)
{
if (x->refcount_.fetch_sub(1, boost::memory_order_release) == 1) {
boost::atomic_thread_fence(boost::memory_order_acquire);
delete x;
}
}
1: the fetch_sub op is limited by memory_order_release, which prevents preceding operations to be reordered past the point. But what are the possible scenes that would have such phenomenon?
2: in addition of memory_order_release on the atomic op, why there is an additional memory_order_acquire before the deletion?