A shutdown task can still succeed ?

forax at univ-mlv.fr forax at univ-mlv.fr
Tue Feb 8 15:55:37 UTC 2022


> From: "Ron Pressler" <ron.pressler at oracle.com>
> To: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "loom-dev" <loom-dev at openjdk.java.net>
> Sent: Tuesday, February 8, 2022 4:33:52 PM
> Subject: Re: A shutdown task can still succeed ?

> What is the cause of the surprise? The name “shutdown”?
> Shutdown doesn’t mean cancel, but “the scope’s computation is done; I have all
> that I need.” Perhaps a better name is needed. At various times we considered
> “cancelAll”, “complete” and “bail.” All of them have some positive or negative
> connotations, while what we want is something neutral — we’re done, either
> successfully or not. Shutdown seemed neutral enough.

> Therefore, a task that calls shutdown signals that it has what it needs to
> complete the operation, and does not cancel itself. Of course, it can choose to
> fail by throwing an exception.

I see now why shutdown does not cancel the task that calls shutdown because the idea is that the task has a result (or an exception). 

I think i would prefer something like cancelOtherTasks() or stopOtherTasks() than shutdown() because it is what shutdown does, it stops the completion of the other tasks. 

> — Ron

Rémi 

>> On 8 Feb 2022, at 14:11, Remi Forax < [ mailto:forax at univ-mlv.fr |
>> forax at univ-mlv.fr ] > wrote:

>> Hi all,

>> try (var scope = new StructuredTaskScope<>()) {
>> var future1 = scope.fork(() -> {
>> Thread.sleep(1_000);
>> return "task1";
>> });
>> var future2 = scope.fork(() -> {
>> Thread.sleep(50);
>> scope.shutdown(); // explicit shutdown`
>> return "task2";
>> });
>> scope.join();
>> System.out.println("state1 " + future1.state());
>> System.out.println("state2 " + future2.state());
>> }

>> prints
>> state1 FAILED
>> state2 SUCCESS

>> which is surprising !

>> regards,
>> Rémi


More information about the loom-dev mailing list