std::atomic_is_lock_free, ATOMIC_xxx_LOCK_FREE
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <atomic> 中定义
|
||
template< class Atomic > bool atomic_is_lock_free(const volatile Atomic* obj) |
(1) | (C++11 起) |
template< class Atomic > bool atomic_is_lock_free(const Atomic* obj) |
(2) | (C++11 起) |
#define ATOMIC_CHAR_LOCK_FREE /* unspecified */ #define ATOMIC_CHAR16_T_LOCK_FREE /* unspecified */ |
(3) | (C++11 起) |
确定的原子指向的对象的
3) obj
实现无锁的,因为如果通过调用obj->is_lock_free()原文:
Determines if the atomic object pointed to by
obj
is implemented lock-free, as if by calling obj->is_lock_free()扩展到整数常量表达式的值0是从来没有无锁的原子类型,1为内置的原子类型,有时是无锁,并2为内置的原子类型都是无锁的
原文:
Expands to an integer constant expression with value 0 for the built-in atomic types that are never lock-free, to 1 for the built-in atomic types that are sometimes lock-free, and to 2 for the built-in atomic types that are always lock-free.
目录 |
[编辑] 注释
除了std::atomic_flag使用互斥锁或其他锁定操作,而不是使用无锁的原子CPU指令,可以实现所有的原子类型。原子类型,也可以是“有时”无锁的,例如:如果只有对齐的内存访问是自然原子在一个给定的体系结构,未对齐的相同类型的对象,必须使用锁。如果类型是有时无锁,然后被用于确定如果该特定的实例是无锁的功能(1-2)或它的成员函数相当于.
原文:
All atomic types except for std::atomic_flag may be implemented using mutexes or other locking operations, rather than using the lock-free atomic CPU instructions. Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks. If the type is sometimes lock-free, then the function (1-2) or its member function equivalent has to be used to determine if the particular instance is lock-free.
[编辑] 参数
obj | - | 指针的原子对象检查
原文: pointer to the atomic object to examine |
[编辑] 返回值
true如果*obj是无锁的原子,false否则.
原文:
true if *obj is a lock-free atomic, false otherwise.
[编辑] 例外
[编辑] 示例
本章尚未完成 原因:暂无示例 |
[编辑] 另请参阅
检查如果的原子对象是无锁的 原文: checks if the atomic object is lock-free (公共成员函数of std::atomic )
| |
专业的原子操作,std::shared_ptr 原文: specializes atomic operations for std::shared_ptr (函数模板) | |
(C++11) |
无锁的布尔原子类型 (类) |