I couldn't find any mention of the thread safety characteristics of V4L2, except for this e-mail from 2008. It talks about the big kernel lock, which I guess is gone now, right?
Does anybody have any updated information on this? Can I ioctl
(I'm thinking especially about VIDIOC_DQBUF
and VIDIOC_QBUF
) the same V4L2 file descriptor from multiple threads without serialization? The discussion cited above does seem to indicate that the answer is driver-dependent, but I thought I'd ask anyway.
ioctl() is not one of them, so it IS thread-safe. However, ioctl() is a cancellation point, so the thread can be terminated once it reaches ioctl().
Thread safe: Implementation is guaranteed to be free of race conditions when accessed by multiple threads simultaneously. Conditionally safe: Different threads can access different objects simultaneously, and access to shared data is protected from race conditions.
Sockets are not part of C++ Standard so it depends on implementation. Generally they are not thread safe since send is not an atomic operation.
Save this answer. Show activity on this post. Thread safety becomes a concern if there is at least a single entry point which can be accessed by multiple threads. If a piece of code is accessed by multiple threads and is calling other method/class/etc., then all this code tree becomes vulnerable.
The specification does not mention whether V4L2 is thread-safe. However it seems that some implementations actually are thread safe.
POSIX.1-2001 and POSIX.1-2008 require that all functions specified in the standard shall be thread-safe, except some specific functions. ioctl() is not one of them, so it IS thread-safe. However, ioctl() is a cancellation point, so the thread can be terminated once it reaches ioctl().
I think that the correct solution is to assume that V4L2 is not thread-safe and do the locking accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With