Thread tidying.
Add is_started_ boolean to Thread so that we don't read an uncreated
pthread_key_self_, don't start twice or call shutdown when not started.
Don't use a MutexLock in ThreadList::Unregister, as the MutexLock will
hold a copy of self for the thread that's deleted.
Don't memory leak the resume condition variable.
Change-Id: I767968a9f785e560fc9e356a339e684de5ce2ffc
diff --git a/src/thread_list.cc b/src/thread_list.cc
index 45ddd23..ebb63dd 100644
--- a/src/thread_list.cc
+++ b/src/thread_list.cc
@@ -554,7 +554,8 @@
while (self != NULL) {
// Remove and delete the Thread* while holding the thread_list_lock_ and
// thread_suspend_count_lock_ so that the unregistering thread cannot be suspended.
- MutexLock mu(self, *Locks::thread_list_lock_);
+ // Note: deliberately not using MutexLock that could hold a stale self pointer.
+ Locks::thread_list_lock_->ExclusiveLock(self);
CHECK(Contains(self));
// Note: we don't take the thread_suspend_count_lock_ here as to be suspending a thread other
// than yourself you need to hold the thread_list_lock_ (see Thread::ModifySuspendCount).
@@ -563,6 +564,7 @@
delete self;
self = NULL;
}
+ Locks::thread_list_lock_->ExclusiveUnlock(self);
}
// Clear the TLS data, so that the underlying native thread is recognizably detached.