什么是“同步壁垒"? [英] What are the 'synchronized barriers'?

查看:58
本文介绍了什么是“同步壁垒"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我正在阅读 JSR-133食谱关于Doug Lea的 JSR 133的编译器作家 :JavaTM内存模型和线程规范修订版 .

Recently I was reading the page The JSR-133 Cookbook for Compiler Writers by Doug Lea regarding JSR 133: JavaTM Memory Model and Thread Specification Revision.

我在这里读到了这一行:

There I read this line:

内存障碍本身不是同步障碍"

Memory barriers are not themselves "synchronization barriers"

我搜索了一些有关内存障碍同步障碍之间差异的资源,但找不到任何好的方法.我也无法确定同步障碍与Java与其他语言的比较是否有任何区别.

I've searched to find some resources about the differences between memory barriers and synchronized barriers but could not find anything good. I also can't tell if synchronized barriers have any difference in comparison of Java with other languages.

推荐答案

首先,正如@markspace所指出的那样,您正在查看的文档并非旨在作为Java程序员试图理解如何编写线程的文档.正确编码.

First of all, as @markspace points out, the document you are looking at is not intended to as a document for Java programmers trying to understand how to write threaded code correctly.

"这是实现新Java内存模型(JMM)的非官方指南"

"This is an unofficial guide to implementing the new Java Memory Model (JMM)"

因此,如果您正为此目的而阅读它,则可能会不必要地使自己感到困惑.相反,您应该使用Java的更高级别的并发机制(最好!),或者阅读和理解JMM规范.

So if you are reading it for that purpose, you are likely to confuse yourself unnecessarily. You should instead be either using Java's higher level concurrency mechanisms (best!), or reading and understanding the JMM spec.

(我相信)同步屏障(不是同步屏障")是指Java内存模型的术语.

The synchronization barrier (not a "synchronized barrier") is (I believe) referring to terminology the Java Memory Model.

JLS 17.4.4定义了各种动作之间的同步-关系.这种关系意味着两个线程之间的同步:

JLS 17.4.4 defines a synchronizes-with relation between various actions. This relation implies a synchronization between two threads:

同步的边缘的源称为 release ,而目标称为 acquire .

The source of a synchronizes-with edge is called a release, and the destination is called an acquire.

对此我不确定(因为Cookbook文档没有详细说明),但是我认为是同步障碍".Cookbook中的内容指的是 synchronizes-with 边缘的物理实现...可能是这样.

I am not sure about this (because the Cookbook document does not elaborate), but I think that "a synchronization barrier" in the Cookbook is referring to a physical implementation of a synchronizes-with edge ... whatever that might be.

因此,文档在这里所说的是它所指的内存屏障与实现锁等的机制不同.真的很明显.

So what the document is saying here is that the memory barriers it refers to are not the same thing as the mechanisms that implement locks and so on. Which is kind of obvious really.

这篇关于什么是“同步壁垒"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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