Page 1 of 1

does mom_model.2 have data races?

Posted: Mon May 18, 2020 6:26 pm
by sfsiegel
Here is the discussion of mem_model.2 in its entirety:
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.
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.

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.