From 4a7f412e1d932f46f6adf079df4d9ee7279bd795 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Mon, 24 Jan 2011 15:20:05 -0800 Subject: [PATCH] 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 --- libs/utils/Threads.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp index ad9a94f594f58..00d009b14a0d6 100644 --- a/libs/utils/Threads.cpp +++ b/libs/utils/Threads.cpp @@ -799,6 +799,9 @@ void Thread::requestExit() status_t Thread::requestExitAndWait() { + // hold a reference so mThreadExitedCondition is not destroyed before wait() returns + sp strong(mHoldSelf); + if (mThread == getThreadId()) { LOGW( "Thread (this=%p): don't call waitForExit() from this "