Only detach shutdown thread if we attached it
Speculative fix to:
"Request to unregister unattached thread" bug.
Bug: 18713034
Change-Id: I6e69088dd66970c704010397a11e3758cf107ff9
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 @@
}
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 @@
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_) {