I know that the -latomic
flag is required for the atomic
library to be linked in by GCC. However, for some reason std::atomic<int>
doesn't require it to build
while structs do
what is this difference caused by?
I know that the -latomic
flag is required for the atomic
library to be linked in by GCC. However, for some reason std::atomic<int>
doesn't require it to build
while structs do
what is this difference caused by?
If the compiler inlines the __atomic
builtins that std::atomic
uses, the object file won't contain any references to functions that libatomic
defines.
This is normal for most architectures with atomic<size_t>
or smaller, at least with optimization enabled, and sometimes for structs the size of two pointers on some architectures. (But not x86-64 since GCC7, where it chooses not to inline lock cmpxchg16b
even if you compile with -mcx16
, and chooses not to report it as is_lock_free
. https://gcc.gnu.org/ml/gcc-patches/2017-01/msg02344.html)
In your case, as you can see by mousing over the source and looking at the asm, auto newData = atomicData.load();
compiled to mov DWORD PTR [rbp-4], eax
even in your debug built. (With a huge amount of clutter since you disabled optimization.)
© 2022 - 2024 — McMap. All rights reserved.
#include <atomic> struct PropBoardSensorData { float tcTemp1, tcTemp2, tcTemp3; }; int main(){ std::atomic<PropBoardSensorData> atomicData{}; auto newData = atomicData.load(); }
– Cobbett