title: Start and Stop a loop within a Thread in C++
body: <p>I need to start a loop from an event and then stop it from another event.
  My idea was to call the function startDequeuing() when I press the button so that a thread with the loop start and then to terminate this loop putting "dequeuing" variable at false from the function stopDequeuing().</p>
  
  <p>It's the first time I use thread, the program locks when I start the loop I think because the variable 'dequeuing' is locked and inaccessible from outside the thread, am I correct?</p>
  
  <p>How can I solve this problem??</p>
  
  <p>Here there is some code:</p>
  
  <pre><code>void CameraManager::startDequeuing(){
      dequeuing = true;
      std::thread dequeueThread(&amp;CameraManager::dequeueLoop, this);
      dequeueThread.join();
  }
  
  void CameraManager::stopDequeuing(){
      dequeuing = false;
  }
  
  void *CameraManager::dequeueLoop(){
      while(dequeuing){
          highSpeedCamera-&gt;dequeue();
          highSpeedCamera-&gt;enqueue();
      }
  }
  </code></pre>