title: Reuse Boost thread (from threadpool) after interruption or join
body: <p>At the moment I am using a producer consumer model for the rendering portion of a realtime graphics application. The consumer will continually look for data in our queue(infinite loop); however I am fearful that this may cause my simulation to get out of sync of the main loop. I think this is the fast producer slow consumer problem - compounded by the fact that the simulation is restrained to a certain amount of time.</p>
  
  <p><em>Question</em> - <strong>what is the best method to keep this all in balance and make sure the consumer has enough time to finish, but also that the simulation does not move to the next frame before we are finished rendering our current frame(or at least be able to detect this and skip rendering the next frame - or interrupt the current frame being rendered)</strong> I am currently just interrupting and joining after each consumer is finished</p>
  
  <p><em>Second Question:</em> if you look at the code below you will see that I am currently just calling interrupt and join after adding rendering jobs to the queue - this allows the thread all the time it needs to complete its operation, and to respond to the interrupt when finished. <strong>How can I then reuse threads in a thread pool after interrupt_all and join_all are called? (i.e. if i call drawNextFrame again)</strong></p>
  
  <p>The producer is part of the main thread of execution (I don't think this affects anything)</p>
  
  <pre><code>pseudo code:
  
  void renderSystem::init()
  create queue to hold work;
  create consumer threads of type RenderConsumer set to watch our queue; 
  add threads to thread_pool of consumers called 'RenderThreads'
  
  void renderSystem::drawNextFrame()
  for each thread in 'RenderThreads' divy up work; 
  add work assignment to queue;
      //RenderThreads will now successfully start pulling data from our queue
  renderThreads.interupt_all();
  renderThreads.join_all();
  
  int main()
  renderer = renderSystem class;
  renderer.init()
  while(not_gameover)
      renderer.drawNextFrame();
      doOtherCoolStuff();
      profit(?)
  return(0)
  </code></pre>
  
  <p>if you need to look at the consumer class see below:</p>
  
  <pre><code>pseudo code:
  
  RenderConsumer::operator () ()
      while(true)
          try to dequeue from queue
          //digest any packet we get
          for each ( pixel in packet )
              computePrettyStuff()
          //we are now done with packet that we got
          this_thread::interruption_point();
  </code></pre>
  
  <p>I tried to make this simple and quick to digest, thank you for your time</p>