Camera::acquire() is not thread-safe

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu Aug 15 16:37:55 CEST 2024


Hi Hans,

On Thu, Aug 15, 2024 at 04:03:19PM +0200, Hans de Goede wrote:
> Hi All,
> 
> Camera::acquire() claims to be thread-safe, but it relies on
> PipelineHandler::acquire() to provide that thread-safety and
> PipelineHandler::acquire() allows multiple acquires of the same
> pipeline-handler since a single pipeline-handler may register multiple
> cameras.
> 
> So that leaves the following possible race:
> 
> 1. Thread A calls Camera::acquire()
>    and passed the isAccessAllowed() check
> 
> 2. Thread B calls Camera::acquire()
>    and passed the isAccessAllowed() check
> 
> 3. Thread A successfully calls pipe_->acquire()
> 
> 4. Thread B successfully calls pipe_->acquire()

In this example, are threads A and B running in the same process ?

> 5. Thread A calls setState(Private::CameraAcquired)
> 
> 6. Thread B calls setState(Private::CameraAcquired)
> 
> And now we have 2 threads succesfully having acquired the same camera
> which I believe is not supposed to be possible.

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list