Chr*_*ini 26 c++ boost thread-safety shared-ptr libc++
在boost的实现中shared_ptr,它使用宽松的内存排序来增加其引用计数.这似乎是安全的,因为减量使用获取/释放来确保在释放内存之前线程可以看到任何先前的减量.这种方法似乎是正确的,并出现在Herb Sutters 谈论原子论
在libc ++中,实现使用全内存屏障
template <class T>
inline T
increment(T& t) _NOEXCEPT
{
return __sync_add_and_fetch(&t, 1);
}
template <class T>
inline T
decrement(T& t) _NOEXCEPT
{
return __sync_add_and_fetch(&t, -1);
}
} // name
Run Code Online (Sandbox Code Playgroud)
这个决定有理由吗?它们之间是否有任何性能或安全差异?
How*_*ant 34
因为当我编写该代码时,编译器(clang)还没有实现C++ 11原子.我从来没有回过头去清理它.
没有什么微妙的.:-)
| 归档时间: |
|
| 查看次数: |
1299 次 |
| 最近记录: |