简体   繁体   English

为什么std :: atomic_is_lock_free不是静态constexpr?

[英]Why isn't std::atomic_is_lock_free a static constexpr?

I am confused. 我很迷惑。 How is it possible that implementation may know if type is atomic only at runtime? 实现如何才能知道类型是否仅在运行时是原子的?

The compiler may not know what CPU the code will run on, and CPUs may differ in their lock-free capabilities. 编译器可能不知道代码将在哪个CPU上运行,并且CPU的无锁功能可能不同。 For example, a CPU may not support atomic operations on long types (and so a lock may be needed), but if the system has only a single core, they may be atomic automatically because they can't be interrupted and there's no other core to race with (and so nothing special is needed and the type is lock free). 例如,CPU可能不支持long类型的原子操作(因此可能需要锁定),但如果系统只有一个核心,它们可能是原子级的,因为它们不能被中断而且没有其他核心与...比赛(所以没有什么特别需要,并且类型是无锁的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM