发生在Java内存模型中的关系之前 [英] Happens-Before relation in Java Memory Model

查看:185
本文介绍了发生在Java内存模型中的关系之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于JLS ch17 主题和锁定,它说如果一个动作发生在另一个动作之前,然后第一个动作在第二个动作之前可见并且在第我想知道:

Regarding JLS ch17 Threads and Locks, it says "if one action happens-before another, then the first is visible to and ordered before the second"; I wonder:

(1)说之前订购是什么意思?因为即使action_a发生在action_b之前,action_a可以在action_b之后的某些实现中执行,对吗?

(1) What does it really mean by saying "ordered before"? Because even if action_a happens-before action_b, action_a can be executed after action_b in some implementation, right?

(2)如果action_a发生在action_b之前,是否意味着action_a绝不能看到action_b?或者action_a可能看到或看不到action_b?

(2) If action_a happens-before action_b, does it mean action_a MUST NOT see action_b? Or action_a may see or may not see action_b?

(3)如果action_a没有发生 - 在action_b之前,而action_b没有发生 - 在action_a之前,是否意味着action_a可能看到或看不到action_b?

(3) If action_a does NOT happen-before action_b, and action_b does NOT happen-before action_a, does it mean action_a may see or may not see action_b?

(4)之前没有任何循环发生,对吧?

(4) There could not be any cyclic happens-before, right?

任何答案都将不胜感激:)

Any answer would be appreciated :)

推荐答案


(1)它的真正含义是什么说之前订购?因为即使action_a发生在action_b之前,action_a可以在action_b之后执行,在某些实现中,对吗?

(1) What does it really mean by saying "ordered before"? Because even if action_a happens-before action_b, action_a can be executed after action_b in some implementation, right?

发生之前 - 之前因果,而不是时间关系。 action_a action_b 之前进行因果排序,无论它是否真正在它之前执行。然而,在实践中,运行时很难在没有时间顺序的情况下保持因果关系。查看我之前的问题,其中详细介绍了该问题。因果关系。

Happens-before is a causal, not a temporal relationship. action_a is causally ordered before action_b, whether or not it actually executes before it. In practice, however, a runtime would have a really hard time maintaning the causality without temporal order. Check out my earlier question which goes into some detail on the subject of causality.


(2)如果action_a发生在action_b之前,是否意味着action_a绝不能看到action_b?或者action_a可能看到或看不到action_b?

(2) If action_a happens-before action_b, does it mean action_a MUST NOT see action_b? Or action_a may see or may not see action_b?

行动的可见性有一个明确的整体顺序。这由指定格式良好的执行的部分处理。因此,对于 a b 中的任何两个操作, b b都可以看到 a a ,或者以上都不是。理解格式良好的执行概念的一个很好的解读是 Java内存模型示例:好的,坏的和丑的

There is a definite overall order of the visibility of actions to one other. This is dealt with by the section specifying well-formed executions. Therefore, for any two actions a and b, either a is visible to b, or b to a, or none of the above. A good read to understand the notion of well-formed executions is Java Memory Model Examples: Good, Bad, and Ugly.


(3)如果action_a没有发生 - 在action_b之前,并且action_b没有发生-before action_a,是否意味着action_a可能会看到或看不到action_b?

(3) If action_a does NOT happen-before action_b, and action_b does NOT happen-before action_a, does it mean action_a may see or may not see action_b?

是的,两者都是可能的。无论如何都无法保证。

Yes, either is possible. There is no guarantee either way.


(4)之前没有任何循环发生,对吧?

(4) There could not be any cyclic happens-before, right?

发生前必须强加部分排序,而排序的关键属性是无循环。

Happens-before must impose a partial ordering, and the key property of ordering is no loops.

这篇关于发生在Java内存模型中的关系之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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