# HG changeset patch # User wenzelm # Date 1663145207 -7200 # Node ID a64f3496d93a143fb09de521692c6fef3410f3c2 # Parent a6bdf4b889ca9f6432208fdf220efe61b7a8573b clarified signature; diff -r a6bdf4b889ca -r a64f3496d93a src/Pure/System/bash.scala --- a/src/Pure/System/bash.scala Tue Sep 13 23:06:52 2022 +0200 +++ b/src/Pure/System/bash.scala Wed Sep 14 10:46:47 2022 +0200 @@ -146,19 +146,13 @@ } - // JVM shutdown hook - - private val shutdown_hook = Isabelle_Thread.create(() => terminate()) - - try { Runtime.getRuntime.addShutdownHook(shutdown_hook) } - catch { case _: IllegalStateException => } - - // cleanup + private val shutdown_hook = + Isabelle_System.create_shutdown_hook { terminate() } + private def do_cleanup(): Unit = { - try { Runtime.getRuntime.removeShutdownHook(shutdown_hook) } - catch { case _: IllegalStateException => } + Isabelle_System.remove_shutdown_hook(shutdown_hook) script_file.delete() winpid_file.foreach(_.delete()) diff -r a6bdf4b889ca -r a64f3496d93a src/Pure/System/isabelle_system.scala --- a/src/Pure/System/isabelle_system.scala Tue Sep 13 23:06:52 2022 +0200 +++ b/src/Pure/System/isabelle_system.scala Wed Sep 14 10:46:47 2022 +0200 @@ -360,6 +360,23 @@ } + /* JVM shutdown hook */ + + def create_shutdown_hook(body: => Unit): Thread = { + val shutdown_hook = Isabelle_Thread.create(new Runnable { def run: Unit = body }) + + try { Runtime.getRuntime.addShutdownHook(shutdown_hook) } + catch { case _: IllegalStateException => } + + shutdown_hook + } + + def remove_shutdown_hook(shutdown_hook: Thread): Unit = + try { Runtime.getRuntime.removeShutdownHook(shutdown_hook) } + catch { case _: IllegalStateException => } + + + /** external processes **/ /* GNU bash */