title: Pass a queue between threads in c++
body: <p>I'm looking for a way to pass a queue between threads in c++, below is a very basic outline what I want to do. It works as a function but I need to use a separate thread as both the task and main will have separate loops to perform.</p>
  
  <p>here is the function:</p>
  
  <pre><code>void task1(queue &lt;bool&gt; &amp;qPass)
  {
      bool bits[5] = { 1, 0, 0, 1, 1 };
  
      for (int i = 0; i &lt; 5; i++)
      {
          qPass.push(bits[i]);
      }
  
      cout &lt;&lt; "Task:\tpush complete\t(" &lt;&lt; qPass.size() &lt;&lt; ")" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>the main</p>
  
  <pre><code>int main()
  {
      queue &lt;bool&gt; qPass;
      int n;
  
      //thread task(task1, qPass);//thread call doesnt work
      //task.join();
  
      task1(qPass);//function call works
  
      n = qPass.size();
      cout &lt;&lt; "Main:\t";
      for (int i = 0; i &lt; n; i++)
      {
          cout &lt;&lt; qPass.front();
          qPass.pop();
      }
      cout &lt;&lt; "\t(" &lt;&lt; n &lt;&lt; ")" &lt;&lt; endl;
  
      cin.get();
      return 0;
  }
  </code></pre>
  
  <p>If I comment the function call and uncomment the thread calls it will run but the queue in main isn't filled. Thanks in advance.</p>