On Wed, 28 Feb 2024 05:37:05 GMT, Chris Plummer <[email protected]> wrote:
>> test/jdk/com/sun/jdi/InterruptHangTest.java line 146:
>>
>>> 144: // When in precise mode, make sure that every interrupt sent
>>> resulted in
>>> 145: // an InterruptedException. Note the interruptor always ends
>>> up sending
>>> 146: // one extra interrupt at the end.
>>
>> Nit: Why do we need this extra interrupt. Can we re-organize the loop to get
>> rid of this extra interrupt? It will make the logics a little bit more
>> simple.
>
> The extra interrupt is because the interruptor will get another shot at
> interrupting once the interuptee does the following on the last interation
> (not this is done on every iteration of the main interruptee loop)
>
> synchronized(InterruptHangTarg.sync) {
> // Let the interruptor thread know it can start
> interrupting again
> sync.notify();
> }
>
> Avoiding this last notify() would require that it be conditionally avoided on
> the last iteration of the loop (by comparing ii to INTERRUPTS_EXPECTED), and
> then as a result set some sort of flag so the PreciseInterruptor doesn't do
> another Thread.interrupt() after the interruptee wakes it up with the
> sync.notify().
>
> Having a check in the middle of a loop to see if we are on the last iteration
> isn't exactly pretty either. I felt having the extra interrupt() was a better
> choice.
Okay. It makes sense.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17989#discussion_r1505471458