title: VIDIOC_DQBUF hangs on camera disconnection
body: <p>My application is using v4l2 running in a separate thread. If a camera gets disconnected then the user is given an appropriate message before terminating the thread cleanly. This works in the vast majority of cases. However, if the execution is inside the VIDIOC_DQBUF ioctl when the camera is disconnected then the ioctl doesn't return causing the entire thread to lock up. </p>
  
  <p>My system is as follows:</p>
  
  <ul>
  <li>Linux Kernel: 4.12.0</li>
  <li>OS:  Fedora 25</li>
  <li>Compiler: gcc-7.1</li>
  </ul>
  
  <p>The following is a simplified example of the problem function.</p>
  
  <pre><code>// Get Raw Buffer from the camera
  void v4l2_Processor::get_Raw_Frame(void* buffer)
  {
  struct v4l2_buffer buf;
  memset(&amp;buf, 0, sizeof (buf));
  
  buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  buf.memory = V4L2_MEMORY_MMAP;
  
  // Grab next frame
  if (ioctl(m_FD, VIDIOC_DQBUF, &amp;buf) &lt; 0)
  {   // If the camera becomes disconnected when the execution is
      // in the above ioctl, then the ioctl never returns.
  
      std::cerr &lt;&lt; "Error in DQBUF\n";
  }
  
  // Queue for next frame
  if (ioctl(m_FD, VIDIOC_QBUF, &amp;buf) &lt; 0)
  {
      std::cerr &lt;&lt; "Error in QBUF\n";
  }
  
  memcpy(buffer, m_Buffers[buf.index].buff, 
     m_Buffers[buf.index].buf_length);
  }
  </code></pre>
  
  <p>Can anybody shed any light on why this ioctl locks up and what I might do to solve this problem?</p>
  
  <p>I appreciate any help offered.</p>
  
  <p>Amanda</p>