为什么is_lock_free是成员函数? [英] Why is is_lock_free a member function?

查看:174
本文介绍了为什么is_lock_free是成员函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 is_lock_free 需要一个实例(它是一个成员函数)的原因是什么?为什么不是类型的元函数,或者一个静态的 constexpr 成员函数?

What is the reason for why is_lock_free requires an instance (it's a member function)? Why not a metafunction of the type, or a static constexpr member function?

我正在寻找一个实际的实例

I am looking for an actual instance of why it is necessary.

推荐答案

标准允许类型有时无锁。


第29.4节无锁属性

ATOMIC _..._ LOCK_FREE宏指示
对应的原子类型的无锁属性,带有签名和无符号变体
组合在一起。这些属性也适用于原子模板的相应
(partial)特化。值为0
表示类型从不是无锁的。 值为1表示
,类型有时无锁。
值为2表示
类型始终无锁。

The ATOMIC_..._LOCK_FREE macros indicate the lock-free property of the corresponding atomic types, with the signed and unsigned variants grouped together. The properties also apply to the corresponding (partial) specializations of the atomic template. A value of 0 indicates that the types are never lock-free. A value of 1 indicates that the types are sometimes lock-free. A value of 2 indicates that the types are always lock-free.

C ++原子论文n2427 说明了背后的原因:


...提议提供运行时锁查询函数,而不是编译时常量
,因为随后的
平台的实现可以用无锁操作来升级锁定操作,所以
系统将这样的设施抽象为动态
图书馆,我们希望将可能性打开。此外,
我们建议没有硬件原子支持的实现使用
的技术。 ...

... The proposal provides run-time lock-free query functions rather than compile-time constants because subsequent implementations of a platform may upgrade locking operations with lock-free operations, so it is common for systems to abstract such facilities behind dynamic libraries, and we wish to leave that possiblility open. Furthermore, we recommend that implementations without hardware atomic support use that technique. ...

还有( Jesse Good 指出):


提案针对单个对象提供无锁查询功能,允许不可避免地不对准原子变量而不惩罚对齐原子变量的性能

The proposal provides lock-free query functions on individual objects rather than whole types to permit unavoidably misaligned atomic variables without penalizing the performance of aligned atomic variables

这篇关于为什么is_lock_free是成员函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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