本文介绍了C ++中的内存模型:顺序一致性和原子性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题与C ++ 11中的内存模型有关。



在 29.幻灯片是写的

但是,在我以前的帖子中,我了解到C ++内存具有弱内存模型 - 编译器可以按需要重新排序 - 他必须满足 规则。 p>

解决方案

我想通过阅读早期的幻灯片,我想出了这张幻灯片正在谈论的内容:





在幻灯片29上,作者们说一旦你使用 std :: atomic 避免数据族UB,程序就会以程序顺序运行。



这是一个有趣的方式来看看C ++的弱内存模型。






第二部分
$ b

请不要一次性提出两个完全不同的问题。



这个CPU怎么做?问题将更适合作为您稍后问题的一部分:



我已经写了大部分的答案,我会把它放在那里。


I have some questions connected with memory model in C++11.

On https://www.think-cell.com/en/career/talks/pdf/think-cell_talk_memorymodel.pdf on the 29. slide is written

But, in my previous posts I learnt that C++ memory has weak memory model- the compiler can make reorder as he wants- he has to satisfy as if rule.

解决方案

I think I figured out what that slide is talking about, from reading the earlier slides:

So on slide 29, the authors are saying that once you avoid data-race UB using std::atomic, the program runs as-if everything happened in program order.

This is an interesting way to look at C++'s weak memory model. This looks like a good set of slides.


Part two

Please don't make a habit of asking two very different questions at once.

This "how does the CPU do it?" question would be a better fit as part of your later question: Atomicity on x86

I have most of an answer to it already written, which I'll put there instead.

这篇关于C ++中的内存模型:顺序一致性和原子性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:57