Skip to content

Commit e28cedb

Browse files
burblebeetkoeppe
authored andcommitted
CWG1953 Data races and common initial sequence
1 parent 10668dc commit e28cedb

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

source/basic.tex

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,7 +3115,9 @@
31153115
\end{note}
31163116

31173117
\pnum
3118-
A \defn{memory location} is either an object of scalar type that is not a bit-field
3118+
A \defn{memory location} is
3119+
the storage occupied by the object representation of
3120+
either an object of scalar type that is not a bit-field
31193121
or a maximal sequence of adjacent bit-fields all having nonzero width.
31203122
\begin{note}
31213123
Various
@@ -6037,13 +6039,30 @@
60376039
\end{note}
60386040
The value computations of the operands of an
60396041
operator are sequenced before the value computation of the result of the
6040-
operator. If a
6042+
operator.
6043+
The behavior is undefined if
6044+
\begin{itemize}
6045+
\item
60416046
\indextext{side effects}%
6042-
side effect on a memory location\iref{intro.memory} is unsequenced
6043-
relative to either another side effect on the same memory location or
6047+
a side effect on a memory location\iref{intro.memory} or
6048+
\item
6049+
starting or ending the lifetime of an object in a memory location
6050+
\end{itemize}
6051+
is unsequenced relative to
6052+
\begin{itemize}
6053+
\item
6054+
another side effect on the same memory location,
6055+
\item
6056+
starting or ending the lifetime of an object occupying storage that
6057+
overlaps with the memory location, or
6058+
\item
60446059
a value computation using the value of any object in the same memory location,
6045-
and they are not potentially concurrent\iref{intro.multithread},
6046-
the behavior is undefined.
6060+
\end{itemize}
6061+
and the two evaluations are not potentially concurrent\iref{intro.multithread}.
6062+
\begin{note}
6063+
Starting the lifetime of an object in a memory location can end the lifetime of
6064+
objects in other memory locations\iref{basic.life}.
6065+
\end{note}
60476066
\begin{note}
60486067
The next subclause imposes similar, but more complex restrictions on
60496068
potentially concurrent computations.
@@ -6057,6 +6076,9 @@
60576076
i = i++ + 1; // the value of \tcode{i} is incremented
60586077
i = i++ + i; // undefined behavior
60596078
i = i + 1; // the value of \tcode{i} is incremented
6079+
6080+
union U { int x, y; } u;
6081+
(u.x = 1, 0) + (u.y = 2, 0); // undefined behavior
60606082
}
60616083
\end{codeblock}
60626084
\end{example}
@@ -6167,9 +6189,21 @@
61676189
\end{note}
61686190

61696191
\pnum
6170-
Two expression evaluations \defn{conflict} if one of them modifies\iref{defns.access} a memory
6171-
location\iref{intro.memory} and the other one reads or modifies the same
6172-
memory location.
6192+
Two expression evaluations \defn{conflict} if one of them
6193+
\begin{itemize}
6194+
\item
6195+
modifies\iref{defns.access} a memory location\iref{intro.memory} or
6196+
\item
6197+
starts or ends the lifetime of an object in a memory location
6198+
\end{itemize}
6199+
and the other one
6200+
\begin{itemize}
6201+
\item
6202+
reads or modifies the same memory location or
6203+
\item
6204+
starts or ends the lifetime of an object occupying storage that
6205+
overlaps with the memory location.
6206+
\end{itemize}
61736207
\begin{note}
61746208
A modification can still conflict
61756209
even if it does not alter the value of any bits.

0 commit comments

Comments
 (0)