在Unique_ptr上的原子操作 [英] Atomic operations on `unique_ptr`

查看:66
本文介绍了在Unique_ptr上的原子操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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_ptr上的原子操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆