On Thu, 8 Jun 2023 09:38:52 GMT, David Holmes <dhol...@openjdk.org> wrote:
>> Thread.interrupted is used to "get and clear" the current thread's interrupt >> status. When called from a virtual thread, the current implementation always >> clears the carrier's interrupt status. There is no need to do this when the >> interrupt status is not set, it can just read the interrupt status and >> return false in that case. >> >> This was found by Sergey Kuksenko when comparing platform vs. virtual thread >> performance. Once CODETOOLS-7903476 is in a released version of JMH then we >> can start to accumulate benchmarks that execute in virtual threads. >> >> Testing: tier1-5 > > 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. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14361#discussion_r1222820022