libutils: Fix race condition in Thread::requestExitAndWait()

Hold a reference to the thread in requestExitAndWait() so the
condition variable it is waiting on will not be destroyed before
its wait() call returns.

Change-Id: If8b6cf84117203926a4180f43f0224469e92a500
Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
Mike Lockwood 2011-01-24 15:20:05 -08:00 committed by Alex Ray
parent b90c51a725
commit ac61abe286
1 changed files with 3 additions and 0 deletions

View File

@ -799,6 +799,9 @@ void Thread::requestExit()
status_t Thread::requestExitAndWait()
{
// hold a reference so mThreadExitedCondition is not destroyed before wait() returns
sp<Thread> strong(mHoldSelf);
if (mThread == getThreadId()) {
LOGW(
"Thread (this=%p): don't call waitForExit() from this "