From 85aebe3ee2a34bd4940d603fefcd55c74de313f4 Mon Sep 17 00:00:00 2001 From: Keith Mok Date: Fri, 6 May 2022 19:44:39 +0000 Subject: [PATCH] Fix fingerprint aidl race condition then thread is join Even if the shared variable is atomic, it must be modified under the mutex in order to correctly publish the modification to the waiting thread. There is a chance that mThread will miss both mIsDestructing and notify event without a mutex. Bug: 231737939 Test: manual Change-Id: If83a94b766c816b9e4897acb1e89eacdce880c15 --- biometrics/fingerprint/aidl/default/WorkerThread.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/biometrics/fingerprint/aidl/default/WorkerThread.cpp b/biometrics/fingerprint/aidl/default/WorkerThread.cpp index d1a63d07ee..34ebb5ca94 100644 --- a/biometrics/fingerprint/aidl/default/WorkerThread.cpp +++ b/biometrics/fingerprint/aidl/default/WorkerThread.cpp @@ -31,7 +31,10 @@ WorkerThread::WorkerThread(size_t maxQueueSize) WorkerThread::~WorkerThread() { // This is a signal for threadFunc to terminate as soon as possible, and a hint for schedule // that it doesn't need to do any work. - mIsDestructing = true; + { + std::unique_lock lock(mQueueMutex); + mIsDestructing = true; + } mQueueCond.notify_all(); mThread.join(); }