30

C++11 introduces a new memory model that lets the abstract machine "running" C++11 code have a notion about multiple threads. It also introduces a set of memory orders by which memory load/store operations abide.

The wikipedia page of C++20 says that it has

a revised memory model.

The reference it gives says that the memory model of C++11 has a number of flaws, which C++20 will revise.

Could someone please give some examples about the problems that come with C++11's memory model, and how that in C++20 would fix it?

Related question: Introduction to C++11's memory model

Zhiyao
  • 4,152
  • 2
  • 12
  • 21
  • 10
    I am so out of touch with C++ that I can't make a meaningful answer, but if you follow the entry on wikipedia it leads to [P0668R4: Revising the C++ memory model](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0668r4.html) – Peter M Jun 20 '20 at 16:40

1 Answers1

14

As @PeterM suggests, its' a (subjectively) minor change due to issues discovered ex-post-facto with the formalization of the C++11 memory model.

The old model was defined so that different regimes of memory access could be implemented on common architectures using more or less-costly sets of hardware instructions. Specifically, memory_order_acquire and memory_order_release were supposed to be implementable on ARM and Power CPU architectures using some kind of lightweight fence instructions. Unfortunately, it turns out that they can't (!); and this is also true for NVIDIA GPUs, although those weren't really targeted a decade back.

With this being the case, there were two options:

  1. Implement to fit the standard - possible, but then performance would be pretty bad and that wasn't the idea.
  2. Fix the standard to better accommodate these architectures (while not messing up the model completely)

Option 2 was apparently chosen.

For more details, read:

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
einpoklum
  • 118,144
  • 57
  • 340
  • 684