Camera::acquire() is not thread-safe
Hans de Goede
hdegoede at redhat.com
Thu Aug 15 16:50:50 CEST 2024
Hi,
On 8/15/24 4:37 PM, Laurent Pinchart wrote:
> 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 ?
Yes I'm talking about 2 threads of the same process
racing here.
>> 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,
Hans
More information about the libcamera-devel
mailing list