I have an std::array
of 64-bit structs, where each struct looks like:
MyStruct
{
float _a{0};
float _b{0};
}; // Assume packed
One thread (CPU core) will write the 64-bit object and a second thread (different core) will read it.
I am using Intel x86 architecture and I know 64-bit writes are guaranteed to be atomic, from the Intel Developer Manuals.
However, I'm worried the second thread might cache the value in a register and not detect when the value has changed.
- Will the MESIF protocol guarantee the second thread sees the writes?
- Do I need the
volatile
keyword to tell the compiler another thread might be modifying the memory? - Do I need atomics?
The thread writing the values is extremely performance sensitive and I'd like to avoid memory barriers, mutexes etc if I can.