Medium
std::atomic over a 12-byte struct
MyStruct is a plain 12-byte trivially-copyable struct (three ints, no padding tricks). Is std::atomic<MyStruct> guaranteed to be lock-free, and is value.load() still a correct, race-free way to read it if is_lock_free() returns false?
main.cpp
#include <atomic>
#include <cstdio>
struct MyStruct {
int a;
int b;
int c;
}; // sizeof(MyStruct) == 12, not a power of two
int main() {
std::atomic<MyStruct> value{MyStruct{1, 2, 3}};
std::printf("lock_free: %d\n", value.is_lock_free());
MyStruct read = value.load();
std::printf("%d %d %d\n", read.a, read.b, read.c);
}74 of 117 in C++