Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8309545

Thread.interrupted from virtual thread needlessly resets interrupt status

XMLWordPrintable

    • b02

        Sergey Kuksenko found this issue. If Thread.interrupted (to "get and clear" the interrupt status) is called from a virtual thread then it always resets the carrier's interrupt status. It shouldn't do that when the interrupt status is not set, meaning it should be just a volatile read when not set.

        Here is Sergey's benchmark using a semaphore. Note that we can't add this to the micro benchmark suite until a new version of JMH is released. The output here compares a virtual thread against a platform thread, before/after fixing this issue.

        ```
        Benchmark Mode Cnt Score Error Units
        Locks.Virtual.testFairSemaphore avgt 5 77.582 ± 0.524 ns/op
        Locks.Virtual.testSemaphore avgt 5 71.746 ± 0.407 ns/op
        Locks.testFairSemaphore avgt 5 47.200 ± 2.633 ns/op
        Locks.testSemaphore avgt 5 46.469 ± 0.308 ns/op

        Benchmark Mode Cnt Score Error Units
        Locks.Virtual.testFairSemaphore avgt 5 53.144 ± 0.149 ns/op
        Locks.Virtual.testSemaphore avgt 5 45.381 ± 1.018 ns/op
        Locks.testFairSemaphore avgt 5 47.620 ± 0.688 ns/op
        Locks.testSemaphore avgt 5 46.767 ± 0.676 ns/op
        ```

        and a micro that just calls Thread.interrupted() gives results:

        ```
        it was:
        Benchmark Mode Cnt Score Error Units
        Inter.Virtual.test avgt 4 42.044 ± 0.736 ns/op
        Inter.test avgt 4 1.134 ± 0.120 ns/op

        Benchmark Mode Cnt Score Error Units
        Inter.Virtual.test avgt 4 1.125 ± 0.008 ns/op
        Inter.test avgt 4 1.123 ± 0.013 ns/op
        ```

              alanb Alan Bateman
              alanb Alan Bateman
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: