Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple alignment from cacheline size #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lahwaacz
Copy link

The first commit fixes #1. Also added another commit with some style changes/fixes.

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.

Fixes d36u9#1
- use std::size_t instead of size_t and std::uint64_t instead of
  uint64_t
- avoid useless static_cast<int> with an argument of the type int
- avoid useless creation of std::vector<bool> which was used only for
  counting iterations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage in dynamic objects fails due to alignment
1 participant