RFR: 8288984: Simplification in java.lang.Runtime::exit [v2]
Kim Barrett
kbarrett at openjdk.org
Tue Jul 5 21:55:41 UTC 2022
On Mon, 4 Jul 2022 12:09:46 GMT, David Holmes <dholmes at openjdk.org> wrote:
>>> Is "deadlock" accurate?
>>
>> Yes.
>>
>> In the context of the specification, "shutdown hook" means _application_ shutdown hook - as far as the specification is concerned, application shutdown hooks are the only kind of hooks. Right?
>>
>> For example, the following will deadlock (when run with the changes in this PR):
>>
>>
>> public class TestHook {
>> public static void main(String... arg) {
>> Thread hook = new Thread("my-hook") {
>> @Override
>> public void run() {
>> System.exit(1);
>> }
>> };
>> Runtime.getRuntime().addShutdownHook(hook);
>> System.exit(0);
>> }
>> }
>
> It is a general deadlock, not a monitor based deadlock: the thread that called exit and holds the lock has to join() the hook thread. The hook thread blocks on the lock held by the exiting thread. Neither thread can progress.
You folks are correct. I hadn't noticed the ApplicationShutdownHooks thing. Sorry for the noise.
-------------
PR: https://git.openjdk.org/jdk/pull/9351
More information about the core-libs-dev
mailing list