RFR: 8315351: Rid synchronization in PipedInputStream.close() in favour of benign race
Vyom Tewari
vtewari at openjdk.org
Wed Aug 30 11:13:08 UTC 2023
On Wed, 30 Aug 2023 09:49:39 GMT, Sergey Tsypanov <stsypanov at openjdk.org> wrote:
> Assuming that the value written into `in` is always `-1` we can rid synchronized block in favour of guarding `in = - 1` with writing into volatile `closedByReader `:
>
> public void close() throws IOException {
> closedByReader = true;
> synchronized (this) {
> in = -1;
> }
> }
>
> -->
>
> public void close() throws IOException {
> in = -1;
> closedByReader = true;
> }
src/java.base/share/classes/java/io/PipedInputStream.java line 448:
> 446: @Override
> 447: public void close() throws IOException {
> 448: in = -1;
I am not sure if this is write thing to do, variable 'in' is accessed from "synchronized void receive(byte[] b, int off, int len)". What if 'close()' is called simultaneously ?.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15486#discussion_r1310102524
More information about the core-libs-dev
mailing list