c++ - atomic<T*> 总是无锁的吗?

标签 c++ c++11 std stdatomic

在我的 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/

相关文章:

c++ - C++中正确的工厂模式

c++ - 带有可变参数的 std::function 列表如何工作

c++ - 将指向常量指针的指针传递给字节数组的语义冲突

c++ - UniversalindentGUI "(STDERR):Cannot find file indentinput.cpp"错误

c++ - g++ : should --std option change which STL/stdlib my code uses?

c++ - Clang++ 不理解 mac 终端中的 c++11

c++ - 使用C++标准库进行字符串混淆

c++ - 是否有任何编译器支持 constexpr?

c++ - Eclipse 处理多个项目

c++ - 如何读取 C++ 中的 JSON 内容?