【发布时间】:2021-06-16 08:57:37
【问题描述】:
根据cppreference,要确定std::hardware_constructive_interference_size 是否可用,它使用以下示例:
#include <new>
#ifdef __cpp_lib_hardware_interference_size
using std::hardware_constructive_interference_size;
using std::hardware_destructive_interference_size;
#else
// 64 bytes on x86-64 │ L1_CACHE_BYTES │ L1_CACHE_SHIFT │ __cacheline_aligned │ ...
constexpr std::size_t hardware_constructive_interference_size
= 2 * sizeof(std::max_align_t);
constexpr std::size_t hardware_destructive_interference_size
= 2 * sizeof(std::max_align_t);
#endif
但是,我的系统定义了__cpp_lib_hardware_interference_size,但没有符号std::hardware_constructive_interference_size。
我该如何处理这种情况?
有没有办法检查一个符号是否被定义?
- Apple clang 版本 12.0.0 (clang-1200.0.32.29)
目标:x86_64-apple-darwin19.6.0
线程模型:posix
安装目录:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin - macOS Catalina 10.15.7(MacBook Pro 2019)
CMakeLists.txt
cmake_minimum_required(VERSION 3.19)
project(untitled4)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
if (UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif()
add_executable(untitled4 main.cpp)
【问题讨论】:
-
打印
__cpp_lib_hardware_interference_size有什么价值?是>= 201703L吗?在阅读 an old LLVM mail thread 时,我注意到他们非常不愿意将其实际添加到他们的库中,而是考虑向标准委员会写一份缺陷报告。 -
打印
201703。这很奇怪......根据stackoverflow.com/a/39887282/8176989 的评论,该提案的作者在 Apple Clang 团队工作。 -
嗯,提案必须来自 somewhere :-) Afaik,gcc 也没有实现这一点。我很惊讶功能测试宏“撒谎”。我的
clang++-12(在 linux 上)没有定义那个宏。