std::shared_ptr 具有原子操作的专业化,例如atomic_compare_exchange_weak和家族,但我找不到有关std::unique_ptr的等效专业化的文档.有吗如果没有,为什么不呢?
std::shared_ptr has specializations for atomic operations like atomic_compare_exchange_weak and family, but I cannot find documentation on equivalent specializations for std::unique_ptr. Are there any? If not, why not?
推荐答案没有std::unique_ptr的标准原子功能.
No there no standard atomic functions for std::unique_ptr.
我确实在 Herb Sutter撰写的>原子智能指针(N4058)"
劳伦斯·克劳尔(Lawrence Crowl)回应添加:
Lawrence Crowl responded to add:
shared_ptr锁定之所以是这种方式,其原因之一是避免了这样一种情况,即我们削弱了原子模板参数的先决条件,因为该前提条件很琐碎,因此没有死锁的风险.
One of the reasons that shared_ptr locking is the way it is is to avoid a situation in which we weaken the precondition on the atomic template parameter that it be trivial, and hence have no risk of deadlock.
也就是说,我们可以削弱要求,以使参数类型仅需要无锁,或者可能仅是非递归锁.
That said, we could weaken the requirement so that the argument type only needs to be lockfree, or perhaps only non-recursively locking.
但是,尽管琐碎的事情可以使可测试的特征变得合理,但我认为没有有效的机制来测试较弱的特性.
However, while trivial makes for reasonably testable traits, I see no effective mechanism to test for the weaker property.
该提案已分配给并发"子组,并且尚未进行处置.您可以在 JTC1/SC22/WG21-Papers 2014中查看状态 mailing2014-07
That proposal has been assigned to the Concurrency Subgroup and has no disposition as of yet. You can check the status at JTC1/SC22/WG21 - Papers 2014 mailing2014-07
更多推荐
在Unique
发布评论