Doc. No.: | WG21/P0371R0 |
---|---|
Date: | 2016-05-26 |
Author: | Hans-J. Boehm |
Email: | hboehm@google.com |
Target: | SG1, then probably CWG |
It is widely accepted that the current definition of
memory_order_consume
in the standard is not useful.
All current compilers essentially map it to
memory_order_acquire
.
The difficulties appear to stem both from the high implementation complexity,
from the fact that the current definition uses a fairly general definition
of "dependency", thus requiring frequent and inconvenient use of the
kill_dependency
call, and from the
frequent need for [[carries_dependency]]
annotations.
Details can be found in e.g.
P0098R0.
Nonetheless, it is also widely accepted that memory_order_consume
has frequent and important use cases in many large code bases. For example,
the Linux kernel makes extensive use of RCU, which relies on this facility
for weakly ordered architectures like ARM and Power.
Some core Android code similarly relies on dependency-based ordering.
Currently there is no way to express this code in a way that is both performant
and standard-conforming.
Thus SG1 continues to discuss improved, more usable, versions. See
P0190R1 or successors. It is likely that any such revision will not be
fully backwards-compatible with the old one, but will better support
common use cases.
The current expectation is that the replacement facility will rely on
core memory model and atomics definitions very similar to what's currently
there. Since memory_order_consume
does have a profound impact
on the memory model, removing this text would allow drastic simplification,
but conversely would make it very difficult to add anything along the lines of
memory_order_consume
back in later, especially if the standard
evolves in the meantime, as expected. Thus we are not proposing to
remove the current wording.
It is not feasible to move all affected text to Annex D, but there
seem be precedents (e.g. D.2) for defining features in the body of the
standard and declaring them deprecated here. It is also unsafe to
simply remove memory_order_consume
from the enumeration
type to which it belongs,
since this would change the value of the other enumeration constants.
And we know that there is important code that relies on those, even
aside from ABI issues. Thus we propose the following relatively
small changes:
Add a new paragraph to Annex D:
D.? memory_order_consume [depr.consume]
The use of
memory_order_consume
is deprecated. [Note:Memory_order_acquire
may be used instead.Memory_order_consume
replacements with somewhat different meaning are under consideration for a future version of the standard. --end note]
It is unclear what to do with the kill_dependency
function and
the carries_dependency
attribute. My sense is that we will want to
approximately preserve kill_dependency
, but that
carries_dependency
will probably need to be specified significantly
differently. Carries_dependency
is also better isolated from
everything else. Thus I suggest moving only carries_dependency
.
Move section 7.6.4 [dcl.attr.depend] to Annex D. Add an introductory sentence:
One additional attribute-token (7.6.1 [dcl.attr.grammar]) is specified.