[libcamera-devel] [PATCH] libcamera: base: thread: Protect exitCode by mutex in exit()

Umang Jain umang.jain at ideasonboard.com
Mon Jun 20 07:11:50 CEST 2022


From: Hirokazu Honda <hiroh at chromium.org>

Thread::exit() accesses data_->exitCode without acquiring a lock.
Fix it.

Signed-off-by: Hirokazu Honda <hiroh at chromium.org>
Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
---
 src/libcamera/base/thread.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp
index 6bda9d14..ff65641e 100644
--- a/src/libcamera/base/thread.cpp
+++ b/src/libcamera/base/thread.cpp
@@ -392,7 +392,10 @@ void Thread::finishThread()
  */
 void Thread::exit(int code)
 {
+	data_->mutex_.lock();
 	data_->exitCode_ = code;
+	data_->mutex_.unlock();
+
 	data_->exit_.store(true, std::memory_order_release);
 
 	EventDispatcher *dispatcher = data_->dispatcher_.load(std::memory_order_relaxed);
-- 
2.31.1



More information about the libcamera-devel mailing list