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.
Example 1 is the following:
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_ceilhere, 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:
Why is
alignas(sizeof(together))being done? The two issues mentioned above are also present here.