Java内存模型和C ++ 11内存模型之间有什么相似之处? [英] What are the similarities between the Java memory model and the C++11 memory model?

查看:120
本文介绍了Java内存模型和C ++ 11内存模型之间有什么相似之处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的c ++标准引入了内存模型的概念。已经有关于SO的问题,它是什么意思,它是如何改变我们在c ++中编写代码的方式等等。

The new c++ standard introduces the notion of a memory model. There were already questions on SO about it, what does it mean, how does it change the way we write code in c++ and so on.

我有兴趣知道C ++内存模型如何与较老的,众所周知的java内存模型(1.5)相关。是一样吗?是类似吗?他们有什么重大差异吗?如果是的话,为什么?

I'm interested in getting to know how does the C++ memory model relate to the older, well known java memory model (1.5). Is it the same? Is it similar? Do they have any significant differences? If so, why?

java内存模型已经存在很长时间了,许多人都知道它很正常,所以我想这可能是有帮助的,不仅是

The java memory model has been around since a long time and many people know it quite decently, so I guess it might be helpful, not only for me, to learn the C++ memory model, by comparing it with the java one.

推荐答案

Java内存模型是一个重要的影响因素在C ++ 11内存模型上,并且是我们从中提取 happens-before 同步的术语。但是,C ++ 11内存模型对内存排序提供了比Java内存模型更精细的控制。

The Java memory model was an important influence on the C++11 memory model, and was where we pulled the terms happens-before and synchronizes-with from. However, the C++11 memory model offers much more fine-grained control over memory ordering than the Java memory model.

Java volatile 变量等价于C ++ 11 std :: atomic<> 变量,如果使用 std :: memory_order_acquire 读取的内存排序, std :: memory_order_release 订阅写入, std :: memory_order_acq_rel

Java volatile variables are equivalent to C++11 std::atomic<> variables, if you use std::memory_order_acquire memory ordering for reads, std::memory_order_release ordering for writes, and std::memory_order_acq_rel ordering for RMW operations.

在Java中没有等同于 std :: memory_order_relaxed std :: memory_order_seq_cst

There is no equivalent in Java to std::memory_order_relaxed, or std::memory_order_seq_cst.

这篇关于Java内存模型和C ++ 11内存模型之间有什么相似之处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆