But isn't it true that all accesses to shared variables in this example are involved in data races? I assumed this was the case, because there are no release or acquire flushes (neither explicit nor implicit), and therefore no happens-before ordering between operations from different threads.The following example demonstrates why synchronization is difficult to perform correctly through variables. The value of flag is undefined in both prints on thread 1 and the value of data is only well-defined in the second print.
My understanding is that if an execution has two threads accessing the same variable, at least one of the accesses is a write, they are not both atomic, and neither operation "happens before" the other, then there is a data race. If that's not right, I'd like to know.