【发布时间】:2014-08-14 09:06:38
【问题描述】:
在boost::atomic的例子中,unref函数:
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:fetch_sub 操作受 memory_order_release 的限制,这可以防止之前的操作在该点之后重新排序。但是有哪些可能的场景会出现这种现象呢?
2:原子操作上除了memory_order_release外,为什么在删除前还有一个memory_order_acquire?
【问题讨论】:
-
sub是 RMW 操作。
标签: c++ boost atomic memory-model refcounting