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) 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) 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) 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) There could not be any cyclic happens-before, right?
Any answer would be appreciated :)
(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?
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) 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?
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) 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) 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With