title: boost thread_group infinite loop
body: <p>I am using boost and trying to create a basic thread_group that will perform their tasks and exit. Here's what my code looks like:</p>
  
  <pre><code>boost::thread_group threads;
  void InputThread()
  {
      int counter = 0;
  
      while(1)
      {
          cout &lt;&lt; "iteration #" &lt;&lt; ++counter &lt;&lt; " Press Enter to stop" &lt;&lt; endl;
  
          try
          {
              boost::this_thread::sleep(boost::posix_time::milliseconds(500));
          }
          catch(boost::thread_interrupted&amp;)
          {
              cout &lt;&lt; "Thread is stopped" &lt;&lt; endl;
              return;
          }
      }
  }
  
  int main()
  {
      int iterator;
      char key_pressed;
      boost::thread t[NUM_THREADS];
  
      for(iterator = 0; iterator &lt; NUM_THREADS; iterator++)
      {
          threads.create_thread(boost::bind(&amp;InputThread)) ;
          cout &lt;&lt; "iterator is: " &lt;&lt; iterator &lt;&lt; endl;
  
             // Wait for Enter to be pressed      
          cin.get(key_pressed);
  
          // Ask thread to stop
          t[iterator].interrupt();
  
      }
      // Join all threads
      threads.join_all();
  
      return 0;
  }
  </code></pre>
  
  <p>I started with two threads and fall in an infinite loop after both the threads are done with their jobs. Something like below:</p>
  
  <pre><code>iterator is: 0
  iteration #1 Press Enter to stop
  iteration #2 Press Enter to stop
  
  iterator is: 1
  iteration #1 Press Enter to stop
  iteration #3 Press Enter to stop
  iteration #2 Press Enter to stop
  
  iteration #4 Press Enter to stop
  iteration #3 Press Enter to stop
  iteration #5 Press Enter to stop
  iteration #4 Press Enter to stop
  iteration #6 Press Enter to stop
  iteration #5 Press Enter to stop
  iteration #7 Press Enter to stop
  ^C
  </code></pre>
  
  <p>Where am I going wrong?</p>