commit 7f425b9b4faa936d0e57c69bbe7f1b3eee46ebb5 Author: Richard Reingruber Date: Tue Jan 16 09:14:07 2024 +0100 Sleep in Thread::interrupt to expose race diff --git a/src/java.base/share/classes/java/lang/Thread.java b/src/java.base/share/classes/java/lang/Thread.java index c3a6a3de5bc..3f27d0edf75 100644 --- a/src/java.base/share/classes/java/lang/Thread.java +++ b/src/java.base/share/classes/java/lang/Thread.java @@ -1659,6 +1659,11 @@ public final void stop() { throw new UnsupportedOperationException(); } + /** + * Just for debugging. + */ + public static volatile boolean dbgSleepInInterrupt; + /** * Interrupts this thread. * @@ -1718,6 +1723,11 @@ public void interrupt() { return; } } + if (dbgSleepInInterrupt) { + try { + Thread.sleep(2000); + } catch(Throwable t) { /* ignored*/ } + } interrupted = true; interrupt0(); // inform VM of interrupt } diff --git a/src/java.base/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java b/src/java.base/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java index 6adf2eb2276..ee36a56b5c3 100644 --- a/src/java.base/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java +++ b/src/java.base/share/classes/java/nio/channels/spi/AbstractInterruptibleChannel.java @@ -174,6 +174,11 @@ private void trySetTarget(Thread target) { * closing and interruption for this channel.

*/ protected final void begin() { + if (Thread.dbgSleepInInterrupt) { + try { + Thread.sleep(1000); + } catch(Throwable t) { /* ignored*/ } + } blockedOn(interruptor); Thread me = Thread.currentThread(); if (me.isInterrupted()) {