- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
is_lock_free
需要一个实例(它是一个成员函数)的原因是什么?为什么不是该类型的元函数或静态 constexpr
成员函数?
我正在寻找一个实际的例子来说明为什么它是必要的。
最佳答案
标准允许类型有时是无锁的。
section 29.4 Lock-free property
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++ atomic paper 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
关于c++ - 为什么 is_lock_free 是一个成员函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39337508/
is_lock_free 需要一个实例(它是一个成员函数)的原因是什么?为什么不是该类型的元函数或静态 constexpr 成员函数? 我正在寻找一个实际的例子来说明为什么它是必要的。 最佳答案 标准
is_lock_free 需要实例(它是成员函数)的原因是什么?为什么不是该类型的元函数,或者静态 constexpr 成员函数? 我正在寻找一个实际的例子来说明为什么它是必要的。 最佳答案 标准允许
谁能告诉我std::atomic::is_lock_free()是否像constexpr一样不是静态的?使它为非静态和/或为非constexpr对我来说没有任何意义。 最佳答案 如cppreferen
一点C++11的代码: #include #include struct A { int a[4]; }; struct B { int x, y; }; int main() { std::
以前,在 Apple LLVM 9.1.0 中,128 位结构上的 is_lock_free() 已返回 true。为了获得完整的 std::optional 支持,我随后升级到 MacPorts g
我遇到这个编译器错误 function std::atomic::is_lock_free() const: error: undefined reference to '__atomic_is_lo
我是一名优秀的程序员,十分优秀!