Skip to content

[hardware.interference] Bad examples of using alignas #9007

@Halalaluyafail3

Description

@Halalaluyafail3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lwgIssue must be reviewed by LWG.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions