title: Reusing thread in loop c++
body: <p>I need to parallelize some tasks in a C++ program and am completely new to parallel programming.  I've made some progress through internet searches so far, but am a bit stuck now.  I'd like to reuse some threads in a loop, but clearly don't know how to do what I'm trying for.</p>
  
  <p>I am acquiring data from two ADC cards on the computer (acquired in parallel), then I need to perform some operations on the collected data (processed in parallel) while collecting the next batch of data.  Here is some pseudocode to illustrate</p>
  
  <pre><code>//Acquire some data, wait for all the data to be acquired before proceeding
  std::thread acq1(AcquireData, boardHandle1, memoryAddress1a);
  std::thread acq2(AcquireData, boardHandle2, memoryAddress2a);
  acq1.join();
  acq2.join();
  
  while(user doesn't interrupt)
  {
  
  //Process first batch of data while acquiring new data
  std::thread proc1(ProcessData,memoryAddress1a);
  std::thread proc2(ProcessData,memoryAddress2a);
  acq1(AcquireData, boardHandle1, memoryAddress1b);
  acq2(AcquireData, boardHandle2, memoryAddress2b);
  acq1.join();
  acq2.join();
  proc1.join();
  proc2.join();
  /*Proceed in this manner, alternating which memory address 
  is written to and being processed until the user interrupts the program.*/
  }
  </code></pre>
  
  <p>That's the main gist of it.  The next run of the loop would write to the "a" memory addresses while processing the "b" data and continue to alternate (I can get the code to do that, just took it out to prevent cluttering up the problem).</p>
  
  <p>Anyway, the problem (as I'm sure some people can already tell) is that the second time I try to use acq1 and acq2, the compiler (VS2012) says "IntelliSense: call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type".  Likewise, if I put std::thread in front of acq1 and acq2 again, it says "  error C2374: 'acq1' : redefinition; multiple initialization".  </p>
  
  <p>So the question is, can I reassign threads to a new task when they have completed their previous task?  I always wait for the previous use of the thread to end before calling it again, but I don't know how to reassign the thread, and since it's in a loop, I can't make a new thread each time (or if I could, that seems wasteful and unnecessary, but I could be mistaken).</p>
  
  <p>Thanks in advance</p>