You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The purpose of the cacheline-size padding between class members is to
avoid false sharing when threads modify the atomic members, but they do
not have to be aligned exactly to the cacheline-size. The atomic members
are very small (just 4 or 8 bytes) compared to the cacheline. As far as
I can tell, their explicit alignment does not matter, they can be placed
anywhere on the cacheline - we just need to ensure they are mapped to
different cachelines.
To avoid problems with misaligned dynamic allocation, the alignment must
not be stricter than alignof(std::max_align_t), which is 16 bytes on
x86_64 Linux. The value was added to the traits structs.
Fixesd36u9#1
async::queue
and all classes using it have alignment requirements, which does not play nice with dynamic objects in C++.Consider the following code:
Compile it with
g++ -pthread -g -fsanitize=undefined code.cpp
, then the typical output may look like(The error output is actually much longer.)
This is because the dynamic allocation in C++ is not required to satisfy alignment requirements stricter than the
std::max_align_t
type (which requires only 16 bytes compared to 64 bytes of theasync::threadpool
). See https://stackoverflow.com/a/53485295 and https://stackoverflow.com/a/16510895/4180822 for details.The text was updated successfully, but these errors were encountered: