Basic questions on semantics of release and acquire flushes

OpenMP 5.0 will be the next version of the OpenMP specification, which we expect will be officially released in 2018. This technical report is the latest draft of the 5.0 specs for public discussion.
Forum rules
The OpenMP Forums are now closed to new posts. Please visit Stack Overflow if you are in need of help: https://stackoverflow.com/questions/tagged/openmp
Locked
sfsiegel
Posts: 12
Joined: Mon Mar 24, 2014 4:47 pm

Basic questions on semantics of release and acquire flushes

Post by sfsiegel »

According to Sec. 2.20.7 (atomic construct), if thread 1 executes

#pragma omp atomic write release
x=1;

then thread 1 performs the following operations, in order:

1. a release flush, which completes, then
2. the assignment x=1, then
3. a strong flush on x, which could complete some time in the future.

If thread 2 executes

#pragma omp atomic read acquire
tmp=x;

then thread 2 performs the following operations, in order:

1. a strong flush on x, which must complete, then
2. a read tmp=x
3. an acquire flush

How can these operations guarantee that the value 1 written by thread 1 is
read by thread 2, when according to Sec. 1.4.4., what is required is
that "the following sequence of events happen in the specified order:

1. The value is written to the variable by the first thread.
2. The first thread performs a release flush.
3. The second thread performs an acquire flush.
4. The value is read from the variable by the second thread."

I.e., we need to have the release flush happen after the assignment
x=1, not before it, and we need to have the acquire flush happen
before the read tmp=x, not after it. And somehow we need to have the
acquire flush happen after the release flush.

I think this mechanism would be much more clear if there were some
examples with real C (or Fortran) code showing how implicit and
explicit release and acquire flushes can be used to "enforce
consistency between two synchronizing threads’ view of memory".

Locked