在Unique

编程入门 行业动态 更新时间:2024-10-25 16:26:17
本文介绍了在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

本文发布于:2023-06-02 14:19:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/447365.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Unique

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!