Merge "Simplify instance reference offsets."
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc
index 53c2859..35411e2 100644
--- a/runtime/thread_list.cc
+++ b/runtime/thread_list.cc
@@ -51,7 +51,13 @@
   // Detach the current thread if necessary. If we failed to start, there might not be any threads.
   // We need to detach the current thread here in case there's another thread waiting to join with
   // us.
-  if (Contains(Thread::Current())) {
+  bool contains = false;
+  {
+    Thread* self = Thread::Current();
+    MutexLock mu(self, *Locks::thread_list_lock_);
+    contains = Contains(self);
+  }
+  if (contains) {
     Runtime::Current()->DetachCurrentThread();
   }