RFR: 8260366: ExtendedSocketOptions <clinit> can deadlock in some circumstances [v2]

Jaikiran Pai jpai at openjdk.java.net
Thu Feb 18 07:38:42 UTC 2021


On Thu, 18 Feb 2021 07:03:07 GMT, Andrey Turbanov <github.com+741251+turbanoff at openjdk.org> wrote:

>> Hello @turbanoff, do you mean why read it twice - once here and once inside the `synchronized` block?
>
> Yes. Once here and once inside `synchronized` block.
> Reading `volatile` fields cost _something_ on some architectures, so I think we could optimize it a bit.

Hello @turbanoff, the double read is necessary to correctly avoid any race conditions and is a typical strategy used in cases like these. I am not aware of any other alternate more performant strategy, for code like this.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2601


More information about the net-dev mailing list