tmp/tmpqoi6pm84/{from.md → to.md}
RENAMED
|
@@ -15,16 +15,41 @@ execution can be viewed as an interleaving of all its threads. However,
|
|
| 15 |
some kinds of atomic operations, for example, allow executions
|
| 16 |
inconsistent with a simple interleaving, as described below. Under a
|
| 17 |
freestanding implementation, it is *implementation-defined* whether a
|
| 18 |
program can have more than one thread of execution.
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
Implementations should ensure that all unblocked threads eventually make
|
| 21 |
progress. Standard library functions may silently block on I/O or locks.
|
| 22 |
Factors in the execution environment, including externally-imposed
|
| 23 |
thread priorities, may prevent an implementation from making certain
|
| 24 |
guarantees of forward progress.
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
The value of an object visible to a thread *T* at a particular point is
|
| 27 |
the initial value of the object, a value assigned to the object by *T*,
|
| 28 |
or a value assigned to the object by another thread, according to the
|
| 29 |
rules below. In some cases, there may instead be undefined behavior.
|
| 30 |
Much of this section is motivated by the desire to support atomic
|
|
@@ -174,19 +199,15 @@ or undefined. This states that operations on ordinary objects are not
|
|
| 174 |
visibly reordered. This is not actually detectable without data races,
|
| 175 |
but it is necessary to ensure that data races, as defined below, and
|
| 176 |
with suitable restrictions on the use of atomics, correspond to data
|
| 177 |
races in a simple interleaved (sequentially consistent) execution.
|
| 178 |
|
| 179 |
-
The
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
atomic object *M*, as determined by evaluation *B*, shall be the value
|
| 185 |
-
stored by some operation in the visible sequence of *M* with respect to
|
| 186 |
-
*B*. It can be shown that the visible sequence of side effects of a
|
| 187 |
-
value computation is unique given the coherence requirements below.
|
| 188 |
|
| 189 |
If an operation *A* that modifies an atomic object *M* happens before an
|
| 190 |
operation *B* that modifies *M*, then *A* shall be earlier than *B* in
|
| 191 |
the modification order of *M*. This requirement is known as write-write
|
| 192 |
coherence.
|
|
@@ -197,13 +218,13 @@ value computation *B* of *M*, and *A* takes its value from a side effect
|
|
| 197 |
stored by *X* or the value stored by a side effect *Y* on *M*, where *Y*
|
| 198 |
follows *X* in the modification order of *M*. This requirement is known
|
| 199 |
as read-read coherence.
|
| 200 |
|
| 201 |
If a value computation *A* of an atomic object *M* happens before an
|
| 202 |
-
operation *B*
|
| 203 |
-
*X* on *M*, where *X* precedes *B* in the modification order
|
| 204 |
-
This requirement is known as read-write coherence.
|
| 205 |
|
| 206 |
If a side effect *X* on an atomic object *M* happens before a value
|
| 207 |
computation *B* of *M*, then the evaluation *B* shall take its value
|
| 208 |
from *X* or from a side effect *Y* that follows *X* in the modification
|
| 209 |
order of *M*. This requirement is known as write-read coherence.
|
|
@@ -211,22 +232,29 @@ order of *M*. This requirement is known as write-read coherence.
|
|
| 211 |
The four preceding coherence requirements effectively disallow compiler
|
| 212 |
reordering of atomic operations to a single object, even if both
|
| 213 |
operations are relaxed loads. This effectively makes the cache coherence
|
| 214 |
guarantee provided by most hardware available to C++atomic operations.
|
| 215 |
|
| 216 |
-
The
|
| 217 |
-
relation, which depends on the values observed by loads of
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
The execution of a program contains a *data race* if it contains two
|
| 225 |
-
|
| 226 |
-
atomic, and neither happens before the other
|
| 227 |
-
|
|
|
|
| 228 |
mutexes and `memory_order_seq_cst` operations to prevent all data races
|
| 229 |
and use no other synchronization operations behave as if the operations
|
| 230 |
executed by their constituent threads were simply interleaved, with each
|
| 231 |
value computation of an object being taken from the last side effect on
|
| 232 |
that object in that interleaving. This is normally referred to as
|
|
@@ -235,20 +263,29 @@ programs, and data-race-free programs cannot observe most program
|
|
| 235 |
transformations that do not change single-threaded program semantics. In
|
| 236 |
fact, most single-threaded program transformations continue to be
|
| 237 |
allowed, since any program that behaves differently as a result must
|
| 238 |
perform an undefined operation.
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
Compiler transformations that introduce assignments to a potentially
|
| 241 |
shared memory location that would not be modified by the abstract
|
| 242 |
machine are generally precluded by this standard, since such an
|
| 243 |
assignment might overwrite another assignment by a different thread in
|
| 244 |
cases in which an abstract machine execution would not have encountered
|
| 245 |
a data race. This includes implementations of data member assignment
|
| 246 |
that overwrite adjacent members in separate memory locations. Reordering
|
| 247 |
of atomic loads in cases in which the atomics in question may alias is
|
| 248 |
-
also generally precluded, since this may violate the
|
| 249 |
-
rules.
|
| 250 |
|
| 251 |
Transformations that introduce a speculative read of a potentially
|
| 252 |
shared memory location may not preserve the semantics of the C++program
|
| 253 |
as defined in this standard, since they potentially introduce a data
|
| 254 |
race. However, they are typically valid in the context of an optimizing
|
|
|
|
| 15 |
some kinds of atomic operations, for example, allow executions
|
| 16 |
inconsistent with a simple interleaving, as described below. Under a
|
| 17 |
freestanding implementation, it is *implementation-defined* whether a
|
| 18 |
program can have more than one thread of execution.
|
| 19 |
|
| 20 |
+
A signal handler that is executed as a result of a call to the `raise`
|
| 21 |
+
function belongs to the same thread of execution as the call to the
|
| 22 |
+
`raise` function. Otherwise it is unspecified which thread of execution
|
| 23 |
+
contains a signal handler invocation.
|
| 24 |
+
|
| 25 |
Implementations should ensure that all unblocked threads eventually make
|
| 26 |
progress. Standard library functions may silently block on I/O or locks.
|
| 27 |
Factors in the execution environment, including externally-imposed
|
| 28 |
thread priorities, may prevent an implementation from making certain
|
| 29 |
guarantees of forward progress.
|
| 30 |
|
| 31 |
+
Executions of atomic functions that are either defined to be lock-free (
|
| 32 |
+
[[atomics.flag]]) or indicated as lock-free ([[atomics.lockfree]]) are
|
| 33 |
+
*lock-free executions*.
|
| 34 |
+
|
| 35 |
+
- If there is only one unblocked thread, a lock-free execution in that
|
| 36 |
+
thread shall complete. Concurrently executing threads may prevent
|
| 37 |
+
progress of a lock-free execution. For example, this situation can
|
| 38 |
+
occur with load-locked store-conditional implementations. This
|
| 39 |
+
property is sometimes termed obstruction-free.
|
| 40 |
+
- When one or more lock-free executions run concurrently, at least one
|
| 41 |
+
should complete. It is difficult for some implementations to provide
|
| 42 |
+
absolute guarantees to this effect, since repeated and particularly
|
| 43 |
+
inopportune interference from other threads may prevent forward
|
| 44 |
+
progress, e.g., by repeatedly stealing a cache line for unrelated
|
| 45 |
+
purposes between load-locked and store-conditional instructions.
|
| 46 |
+
Implementations should ensure that such effects cannot indefinitely
|
| 47 |
+
delay progress under expected operating conditions, and that such
|
| 48 |
+
anomalies can therefore safely be ignored by programmers. Outside this
|
| 49 |
+
International Standard, this property is sometimes termed lock-free.
|
| 50 |
+
|
| 51 |
The value of an object visible to a thread *T* at a particular point is
|
| 52 |
the initial value of the object, a value assigned to the object by *T*,
|
| 53 |
or a value assigned to the object by another thread, according to the
|
| 54 |
rules below. In some cases, there may instead be undefined behavior.
|
| 55 |
Much of this section is motivated by the desire to support atomic
|
|
|
|
| 199 |
visibly reordered. This is not actually detectable without data races,
|
| 200 |
but it is necessary to ensure that data races, as defined below, and
|
| 201 |
with suitable restrictions on the use of atomics, correspond to data
|
| 202 |
races in a simple interleaved (sequentially consistent) execution.
|
| 203 |
|
| 204 |
+
The value of an atomic object *M*, as determined by evaluation *B*,
|
| 205 |
+
shall be the value stored by some side effect *A* that modifies *M*,
|
| 206 |
+
where *B* does not happen before *A*. The set of such side effects is
|
| 207 |
+
also restricted by the rest of the rules described here, and in
|
| 208 |
+
particular, by the coherence requirements below.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
If an operation *A* that modifies an atomic object *M* happens before an
|
| 211 |
operation *B* that modifies *M*, then *A* shall be earlier than *B* in
|
| 212 |
the modification order of *M*. This requirement is known as write-write
|
| 213 |
coherence.
|
|
|
|
| 218 |
stored by *X* or the value stored by a side effect *Y* on *M*, where *Y*
|
| 219 |
follows *X* in the modification order of *M*. This requirement is known
|
| 220 |
as read-read coherence.
|
| 221 |
|
| 222 |
If a value computation *A* of an atomic object *M* happens before an
|
| 223 |
+
operation *B* that modifies *M*, then *A* shall take its value from a
|
| 224 |
+
side effect *X* on *M*, where *X* precedes *B* in the modification order
|
| 225 |
+
of *M*. This requirement is known as read-write coherence.
|
| 226 |
|
| 227 |
If a side effect *X* on an atomic object *M* happens before a value
|
| 228 |
computation *B* of *M*, then the evaluation *B* shall take its value
|
| 229 |
from *X* or from a side effect *Y* that follows *X* in the modification
|
| 230 |
order of *M*. This requirement is known as write-read coherence.
|
|
|
|
| 232 |
The four preceding coherence requirements effectively disallow compiler
|
| 233 |
reordering of atomic operations to a single object, even if both
|
| 234 |
operations are relaxed loads. This effectively makes the cache coherence
|
| 235 |
guarantee provided by most hardware available to C++atomic operations.
|
| 236 |
|
| 237 |
+
The value observed by a load of an atomic depends on the “happens
|
| 238 |
+
before” relation, which depends on the values observed by loads of
|
| 239 |
+
atomics. The intended reading is that there must exist an association of
|
| 240 |
+
atomic loads with modifications they observe that, together with
|
| 241 |
+
suitably chosen modification orders and the “happens before” relation
|
| 242 |
+
derived as described above, satisfy the resulting constraints as imposed
|
| 243 |
+
here.
|
| 244 |
+
|
| 245 |
+
Two actions are *potentially concurrent* if
|
| 246 |
+
|
| 247 |
+
- they are performed by different threads, or
|
| 248 |
+
- they are unsequenced, and at least one is performed by a signal
|
| 249 |
+
handler.
|
| 250 |
|
| 251 |
The execution of a program contains a *data race* if it contains two
|
| 252 |
+
potentially concurrent conflicting actions, at least one of which is not
|
| 253 |
+
atomic, and neither happens before the other, except for the special
|
| 254 |
+
case for signal handlers described below. Any such data race results in
|
| 255 |
+
undefined behavior. It can be shown that programs that correctly use
|
| 256 |
mutexes and `memory_order_seq_cst` operations to prevent all data races
|
| 257 |
and use no other synchronization operations behave as if the operations
|
| 258 |
executed by their constituent threads were simply interleaved, with each
|
| 259 |
value computation of an object being taken from the last side effect on
|
| 260 |
that object in that interleaving. This is normally referred to as
|
|
|
|
| 263 |
transformations that do not change single-threaded program semantics. In
|
| 264 |
fact, most single-threaded program transformations continue to be
|
| 265 |
allowed, since any program that behaves differently as a result must
|
| 266 |
perform an undefined operation.
|
| 267 |
|
| 268 |
+
Two accesses to the same object of type `volatile sig_atomic_t` do not
|
| 269 |
+
result in a data race if both occur in the same thread, even if one or
|
| 270 |
+
more occurs in a signal handler. For each signal handler invocation,
|
| 271 |
+
evaluations performed by the thread invoking a signal handler can be
|
| 272 |
+
divided into two groups *A* and *B*, such that no evaluations in *B*
|
| 273 |
+
happen before evaluations in *A*, and the evaluations of such
|
| 274 |
+
`volatile sig_atomic_t` objects take values as though all evaluations in
|
| 275 |
+
*A* happened before the execution of the signal handler and the
|
| 276 |
+
execution of the signal handler happened before all evaluations in *B*.
|
| 277 |
+
|
| 278 |
Compiler transformations that introduce assignments to a potentially
|
| 279 |
shared memory location that would not be modified by the abstract
|
| 280 |
machine are generally precluded by this standard, since such an
|
| 281 |
assignment might overwrite another assignment by a different thread in
|
| 282 |
cases in which an abstract machine execution would not have encountered
|
| 283 |
a data race. This includes implementations of data member assignment
|
| 284 |
that overwrite adjacent members in separate memory locations. Reordering
|
| 285 |
of atomic loads in cases in which the atomics in question may alias is
|
| 286 |
+
also generally precluded, since this may violate the coherence rules.
|
|
|
|
| 287 |
|
| 288 |
Transformations that introduce a speculative read of a potentially
|
| 289 |
shared memory location may not preserve the semantics of the C++program
|
| 290 |
as defined in this standard, since they potentially introduce a data
|
| 291 |
race. However, they are typically valid in the context of an optimizing
|