| OPENMP API Specification: "Version 5.2 -- GIT rev 95b2e3a44"
1.4.5 Flush Synchronization and Happens Before
OpenMP supports thread synchronization with the use of release flushes and acquire flushes. For
any such synchronization, a release flush is the source of the synchronization and an acquire
flush is the sink of the synchronization, such that the release flush synchronizes with the acquire
flush.
A release flush has one or more associated release sequences that define the set of modifications that may be
used to establish a synchronization. A release sequence starts with an atomic operation that follows the
release flush and modifies a shared variable and additionally includes any read-modify-write atomic
operations that read a value taken from some modification in the release sequence. The following rules
determine the atomic operation that starts an associated release sequence.
- If
a
release
flush
is
performed
on
entry
to
an
atomic
operation,
that
atomic
operation
starts
its
release
sequence.
- If
a
release
flush
is
performed
in
an
implicit
flush
region,
an
atomic
operation
that
is
provided
by
the
implementation
and
that
modifies
an
internal
synchronization
variable
starts
its
release
sequence.
- If
a
release
flush
is
performed
by
an
explicit
flush
region,
any
atomic
operation
that
modifies
a
shared
variable
and
follows
the
flush
region
in
its
thread’s
program
order
starts
an
associated
release
sequence.
An acquire flush is associated with one or more prior atomic operations that read a shared variable and that
may be used to establish a synchronization. The following rules determine the associated atomic operation
that may establish a synchronization.
- If
an
acquire
flush
is
performed
on
exit
from
an
atomic
operation,
that
atomic
operation
is
its
associated
atomic
operation.
- If
an
acquire
flush
is
performed
in
an
implicit
flush
region,
an
atomic
operation
that
is
provided
by
the
implementation
and
that
reads
an
internal
synchronization
variable
is
its
associated
atomic
operation.
- If
an
acquire
flush
is
performed
by
an
explicit
flush
region,
any
atomic
operation
that
reads
a
shared
variable
and
precedes
the
flush
region
in
its
thread’s
program
order
is
an
associated
atomic
operation.
A release flush synchronizes with an acquire flush if the following conditions are satisfied:
- An
atomic
operation
associated
with
the
acquire
flush
reads
a
value
written
by
a
modification
from
a
release
sequence
associated
with
the
release
flush;
and
- The
device
on
which
each
flush
is
performed
is
in
both
of
their
respective
device-sets.
An operation X simply happens before an operation Y if any of the following conditions are
satisfied:
-
1.
-
X
and
Y
are
performed
by
the
same
thread,
and
X
precedes
Y
in
the
thread’s
program
order;
-
2.
-
X
synchronizes
with
Y
according
to
the
flush
synchronization
conditions
explained
above
or
according
to
the
base
language’s
definition
of
synchronizes with,
if
such
a
definition
exists;
or
-
3.
-
Another
operation,
Z,
exists
such
that
X
simply
happens
before
Z
and
Z
simply
happens
before
Y.
An operation X happens before an operation Y if any of the following conditions are satisfied:
-
1.
-
X
happens
before
Y
according
to
the
base
language’s
definition
of
happens before,
if
such
a
definition
exists;
or
-
2.
-
X
simply
happens
before
Y.
A variable with an initial value is treated as if the value is stored to the variable by an operation that happens
before all operations that access or modify the variable in the program.