Camera::acquire() is not thread-safe
Hans de Goede
hdegoede at redhat.com
Thu Aug 15 16:03:19 CEST 2024
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()
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