On Wed, 26 Apr 2023 16:45:57 GMT, Tejesh R <t...@openjdk.org> wrote: >> test/jdk/java/awt/ScrollPane/ScrollPaneRemoveAdd.java line 121: >> >>> 119: volatile boolean state = false; >>> 120: Object lock = new Object(); >>> 121: volatile int waiting = 0; >> >> Why are both `state` and `waiting` marked as volatile? Either is accessed >> from synchronized blocks protected by `lock` except for `getState` which >> should also use the `lock` object. > > I don't think its required to be volatile, not sure.
They shouldn't be volatile, a proper synchronisation is used. But `getState` should use `lock` lock to return the state because access to `state` is synchronised using `lock`, not `this`. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/13621#discussion_r1179096063