I'm writing some multithreaded C code, and I just came across this StackOverflow question. It sounds like the compiler will make sure that I/O to different parts of a struct will never intersect or cause some sort of race condition.
My question, as an extension, is that are there similar guarantees for two different structs that are spatially close in shared memory?
Edit: Spatially close as in "same page". Would two writes from two different threads to the same page cause a race condition? One guy could end up flusing a stale page from his cache to memory (is this possible?).
Let's say I have two bits, as their own structs, in shared memory. If they end up being adjacent, can one thread writing to one of them overwrite the other? Would I have to serialize all threads with one lock for access to any of these structs in shared memory?
Or is all of this, and the issue in the referenced question, a risk anyway in C99?