diff options
-rw-r--r-- | runtime/runtime.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc index f38f65e..9a2e901 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -190,7 +190,8 @@ Runtime::~Runtime() { } Thread* self = Thread::Current(); - if (self == nullptr) { + const bool attach_shutdown_thread = self == nullptr; + if (attach_shutdown_thread) { CHECK(AttachCurrentThread("Shutdown thread", false, nullptr, false)); self = Thread::Current(); } else { @@ -212,8 +213,10 @@ Runtime::~Runtime() { self->GetJniEnv()->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons, WellKnownClasses::java_lang_Daemons_stop); } - DetachCurrentThread(); - self = nullptr; + if (attach_shutdown_thread) { + DetachCurrentThread(); + self = nullptr; + } // Shut down background profiler before the runtime exits. if (profiler_started_) { |