RFR: 8309545: Thread.interrupted from virtual thread needlessly resets interrupt status

David Holmes dholmes at openjdk.org
Thu Jun 8 12:09:49 UTC 2023


On Thu, 8 Jun 2023 10:21:07 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/VirtualThread.java line 879:
>> 
>>> 877:         boolean oldValue = interrupted;
>>> 878:         if (oldValue) {
>>> 879:             synchronized (interruptLock) {
>> 
>> Don't you still need to read under the lock to synchronize with the interrupt method?
>
> The override of interrupt for virtual threads always sets the interrupt status as the first step. So if Thread.interrupted reads the interrupt status as true then it will synchronize. It's not too different to platform threads, I think you added a comment to Thread.interrupted about this when move the interrupted flag into Java.

Changing the synchronization means there is a lot more to think about for what was otherwise a fairly trivial change. But I think you are right, if we don't see interrupted==true then we do nothing; if we do see it then we synchronize.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14361#discussion_r1222948182


More information about the core-libs-dev mailing list