// thread_suspend_count_lock_ so that the unregistering thread cannot be suspended.
// 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).
- if (!self->IsSuspended()) {
- list_.remove(self);
- delete self;
+ if (!Contains(self)) {
+ std::ostringstream os;
+ DumpNativeStack(os, GetTid(), " native: ", nullptr);
+ LOG(ERROR) << "Request to unregister unattached thread\n" << os.str();
self = nullptr;
+ } else {
+ // 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).
+ if (!self->IsSuspended()) {
+ list_.remove(self);
+ delete self;
+ self = nullptr;
+ }
}
Locks::thread_list_lock_->ExclusiveUnlock(self);
}