Aliased atomic operations

  atomic, c++, multithreading, undefined-behavior, union

Say that I have the following struct and union:

struct Foo
{
   std::atomic<int> a;
   std::atomic<int> b;
};

union Bar
{
   std::atomic<Foo> x;
   Foo y;
} bar;

Assuming Foo is always lock free, is it safe to perform (64-bit) atomic loads from bar x while concurrently modifying the 32-bit member variables of bar.y?

Source: Windows Questions C++

LEAVE A COMMENT