Doc. No.: WG21/P0371R1
Date: 2016-06-23
Author: Hans-J. Boehm
Email: hboehm@google.com
Target: LWG, maybe CWG

P0371R1: Temporarily discourage memory_order_consume

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.

SG1 did not want to officially deprecate memory_order_consume, as was proposed in Revision 0. But we did want to inform users of the problem. The following reflects this compromise.

Proposed wording

Change 29.3p1.3 [atomics.order] as follows:

-- memory_order_consume: a load operation performs a consume operation on the affected memory location. [Note: Prefer memory_order_acquire, which provides stronger guarantees than memory_order_consume. Implementations have found it infeasible to provide performance better than that of memory_order_acquire. Specification revisions are under consideration. -- end note]