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

Laurent Pinchart laurent.pinchart at ideasonboard.com
Mon Jun 20 10:27:23 CEST 2022


Hi Umang,

Thank you for the patch.

On Mon, Jun 20, 2022 at 10:41:50AM +0530, Umang Jain via libcamera-devel wrote:
> From: Hirokazu Honda <hiroh at chromium.org>
> 
> Thread::exit() accesses data_->exitCode without acquiring a lock.
> Fix it.

Could you explain here why the lock is needed ?

> 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);

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list