std::hardware_constructive_interference_size
STD:硬件[医]破坏性[医]干扰[医]大小,STD::硬件[医]建设性[医]干扰[医]大小
Defined in header | | |
---|---|---|
inline constexpr std::size_t hardware_destructive_interference_size = /*implementation-defined*/; | (1) | (since C++17) |
inline constexpr std::size_t hardware_constructive_interference_size = /*implementation-defined*/; | (2) | (since C++17) |
1%29两个对象之间的最小偏移量,以避免错误共享。保证至少alignof(
std::max_align_t
)
二次
struct keep_apart {
alignas(std::hardware_destructive_interference_size) std::atomic<int> cat;
alignas(std::hardware_destructive_interference_size) std::atomic<int> dog;
};
二次
2%~29最大连续内存大小,促进真正共享。保证至少alignof(
std::max_align_t
)
二次
struct together {
atomic<int> dog;
int puppy;
};
struct kennel {
// Other data members...
alignas(sizeof(together)) together pack;
// Other data members...
};
static_assert(sizeof(together) <= std::hardware_constructive_interference_size
二次
注记
这些常量提供了访问L1数据缓存线大小的可移植方式。
例
另见
hardware_concurrency static | returns the number of concurrent threads supported by the implementation (public static member function of std::thread) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。