Fix race in thread list destructor

The ThreadList::Contains wasn't being guarded by the thread list
lock, which could cause a corrupted thread list if another thread
unregistered itself while std::find was searching the thread list.

Bug: 17896374
Change-Id: I629b1eac3473e3cf7355ebde9080dfd7c58af73a
diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc
index ceed254..b48fcd4 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();
   }