Re: CompletableFuture.get() swallows thread interrupt flag on Java 11
David Holmes via Concurrency-interest <[email protected]> Thu, 15 Oct 2020 17:55:09 +1000
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <[email protected]> |
I think I can see how this happens. At the end of waitingGet we may have been interrupted and already caught the IE, but because we are interruptible we don't re-assert the interrupt status. If we return null that indicates reportGet should throw IE. But before we return from waitingGet we reload from "result" which may now be non-null, so we return non-null and hence never rethrow the IE.
There needs to be a further check of q.interrupted and a re-assertion of the interrupt state, but I'm not certain of the exact state that needs to be checked. Possibly:
If (r != null || (r = result) != null) {
postComplete();
+ if (q != null && q.interrupted && interruptible)
+ Thread.currentThread().interrupt();
}
Cheers,
David
-----Original Message-----
From: Concurrency-interest <[email protected]> On Behalf Of Jens Wilke via Concurrency-interest
Sent: Thursday, 15 October 2020 5:02 PM
To: Alex Otenko <[email protected]>
Cc: concurrency-interest <[email protected]>
Subject: Re: [concurrency-interest] CompletableFuture.get() swallows thread interrupt flag on Java 11
No. Interruption works.
The problem is triggered when interruption and completion happen at the
same time.
On 15/10/20 4:23 pm, Alex Otenko wrote:
> Does it reproduce if you remove the line that completes the future?
_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
_______________________________________________
Concurrency-interest mailing list
[email protected]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest