Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
换句话说,是否std::atomic<int>保证只保存一个int值?
std::atomic<int>
int
不。
根据 C++11 标准的第 29.5/9 段:
[注意:原子特化的表示不需要与其对应的参数类型具有相同的大小。专业化应尽可能具有相同的大小,因为这减少了移植现有代码所需的工作量。——尾注]