在我的 MAC 操作系统上,atomic<T*>
是无锁的。
#include <iostream>
#include <atomic>
int main() {
std::cout << std::atomic<void*>().is_lock_free() << std::endl;
return 0;
}
output: 1
我想知道是否 atomic<T*>
总是无锁?
有引用介绍吗?
最佳答案
The standard allows implementing any atomic type (with exception of std::atomic_flag) to be implemented with locks.即使平台允许某些类型的无锁原子,标准库开发人员也可能没有实现它。
如果您需要在使用锁时实现不同的东西,可以在编译时使用 ATOMIC_POINTER_LOCK_FREE
宏进行检查。
关于c++ - atomic<T*> 总是无锁的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51822290/