cplusplus / cplusplus/draft

[hardware.interference] Bad examples of using alignas

Open
#9,007 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

lwg
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

Example 1 is the following:

struct keep_apart {
  alignas(hardware_destructive_interference_size) atomic<int> cat;
  alignas(hardware_destructive_interference_size) atomic<int> dog;
};

There is nothing specifying that these must be valid alignments, or that they must even be nonnegative integer powers of two. Would it make sense to use something like bit_ceil here, plus a check to handle the case where that result is not representable? That would fix the latter issue, not sure if it is possible to check if something is a valid alignment.

Example 2 is the following:

struct together {
  atomic<int> dog;
  int puppy;
};
struct kennel {
  // Other data members...
  alignas(sizeof(together)) together pack;
  // Other data members...
};
static_assert(sizeof(together) <= hardware_constructive_interference_size);

Why is alignas(sizeof(together)) being done? The two issues mentioned above are also present here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the two hardware interference examples quoted in the issue and review the surrounding standard-draft wording for alignas and alignment requirements. Determine whether the examples need valid-alignment handling and whether alignas(sizeof(together)) is justified. Done means the examples and their explanation no longer imply unsupported alignment assumptions, with the rationale for the second example made clear.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.