<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>P0371R1: Temporarily discourage memory_order_consume</title>
</head>
<body>
<table>
	<tr>
                <th>Doc. No.:</th>
                <td>WG21/P0371R1</td>
        </tr>
        <tr>
                <th>Date:</th>
                <td>2016-06-23</td>
        </tr>
        <tr>
                <th>Author:</th>
                <td>Hans-J. Boehm</td>
        </tr>
        <tr>
                <th>Email:</th>
                <td><a href="mailto:hboehm@google.com">hboehm@google.com</a></td>
        </tr>
        <tr>
                <th>Target:</th>
                <td>LWG, maybe CWG</td>
        </tr>
</table>
<h1>P0371R1: Temporarily discourage memory_order_consume</h1>
<p>
It is widely accepted that the current definition of
<code>memory_order_consume</code> in the standard is not useful.
All current compilers essentially map it to
<code>memory_order_acquire</code>.
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
<code>kill_dependency</code> call, and from the
frequent need for <code>[[carries_dependency]]</code> annotations.
Details can be found in e.g.
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0098r0.pdf">
P0098R0</a>.
<p>
Nonetheless, it is also widely accepted that <code>memory_order_consume</code>
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
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0190r1.pdf">
P0190R1</a> 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.
<p>
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 <code>memory_order_consume</code> 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
<code>memory_order_consume</code> back in later, especially if the standard
evolves in the meantime, as expected.  Thus we are not proposing to
remove the current wording.
<p>
SG1 did not want to officially deprecate <code>memory_order_consume</code>,
as was proposed in Revision 0.
But we did want to inform users of the problem.  The following reflects
this compromise. 

<h2>Proposed wording</h2>
<p>
Change 29.3p1.3 [atomics.order] as follows:
<blockquote>
<p>
-- memory_order_consume: a load operation performs a consume operation on the
affected memory location. <ins>[Note: Prefer <code>memory_order_acquire</code>,
which provides stronger guarantees than <code>memory_order_consume</code>.
Implementations have found it infeasible to provide performance better than
that of <code>memory_order_acquire</code>. Specification revisions are under
consideration. -- end note]</ins>
</blockquote>
</body>
</html>


