On Wed, 26 Aug 2026 10:59:51 GMT, Fabian Meumertzheim <[email protected]> wrote:
>> test/jdk/java/util/concurrent/forkjoin/GetMultipleWaiters.java line 62:
>>
>>> 60: } catch (Throwable ignore) {
>>> 61: }
>>> 62: }, "Get-waiter-B", Thread.State.WAITING);
>>
>> I wonder if we really need `b` if we launch this test in othervm with a
>> timeout. Would you mind trying removing `b` and calling `task.get(…)` on the
>> main thread and seeing if that is enough? It would save a chunk of test case
>> complexity if it pans out.
>
> I may have misunderstood the simplification, but this is what I tried. It did
> not reproduce the issue without the fix applied:
>
>
> /*
> * @test
> * @bug 8390870
> * @summary ForkJoinTask.get must honor its timeout and interrupts even
> * when another thread is waiting on the same task.
> * @run junit/othervm/timeout=20 GetMultipleWaitersSimplified
> */
>
> import java.util.concurrent.ForkJoinTask;
> import java.util.concurrent.TimeUnit;
> import java.util.concurrent.TimeoutException;
>
> import org.junit.jupiter.api.Test;
> import static org.junit.jupiter.api.Assertions.assertThrows;
>
> class GetMultipleWaiters {
>
> /**
> * get() on the main thread must be interruptible while another
> * thread is waiting on the same task.
> */
> @Test
> void testGet() throws Exception {
> var task = ForkJoinTask.adapt(() -> {});
>
> var a = startThreadAndAwaitState(() -> {
> try {
> task.get();
> } catch (Throwable ignore) {
> }
> }, "Get-waiter-A", Thread.State.WAITING);
>
> try {
> Thread.currentThread().interrupt();
> assertThrows(InterruptedException.class, () -> task.get());
> } finally {
> task.complete(null);
> a.join();
> }
> }
> }
>
>
> As far as I understand the CAS bug, this is because the waiter that is
> interrupted needs to be the first on the stack, but here it would be the last.
Ah, yes, apologies, commented on the wrong method. I was thinking about
`testTimedGet()` but `testGet()` won't work because if the main thread calls
`task.get()` it will never wake since it cannot issue the interruption.
However, if in the method that tests the timeout completes `task` upon
exception, it would seem like we could scrap thread `b`, but thinking about it
some more, I don't think it's worth it (since then the two tests would be
different.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/32485#discussion_r3862587517