does mom_model.2 have data races?

Discuss the OpenMP Examples document, updated for OpenMP 5.0
Forum rules
The OpenMP Forums are now closed to new posts. Please visit Stack Overflow if you are in need of help:
Posts: 12
Joined: Mon Mar 24, 2014 4:47 pm

does mom_model.2 have data races?

Post 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.