On Fri, 20 Jun 2025 20:12:52 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:
>> I mean that there's a _happens before_ relation each time the synchronized >> block is reach whereas with volatile, the _happens before_ relation is >> guaranteed only when the value of the variable changes. > >> I mean that there's a _happens before_ relation each time the synchronized >> block is reach whereas with volatile, the _happens before_ relation is >> guaranteed only when the value of the variable changes. > > I do not think that this is true "guaranteed only when the value of the > variable changes". >>A write to a volatile field >>([ยง8.3.1.4](https://docs.oracle.com/javase/specs/jls/se14/html/jls-8.html#jls-8.3.1.4)) >> happens-before every subsequent read of that field. Exactly! A *write* to a volatile field. Yet entering and leaving a synchronized block gives a happens-before relation *each time*. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/25818#discussion_r2159624167