Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How thread-safe is V4L2?

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.

like image 671
gspr Avatar asked Apr 18 '12 20:04

gspr


People also ask

Is ioctl thread safe?

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().

What is considered thread safe?

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.

Are C++ Sockets thread safe?

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.

When should I worry about thread safety?

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.


1 Answers

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.

like image 101
Sergey K. Avatar answered Sep 30 '22 20:09

Sergey K.