title: Boost thread_interrupted exception terminate()s with MinGW gcc 4.4.0, OK with 3.4.5
body: <p>I've been "playing around with" boost threads today as a learning exercise, and I've got a working example I built quite a few months ago (before I was interrupted and had to drop multi-threading for a while) that's showing unusual behaviour.</p>
  
  <p>When I initially wrote it I was using MingW gcc 3.4.5, and it worked. Now I'm using 4.4.0 and it doesn't - incidentally, I've tried again using 3.4.5 (I kept that version it a separate folder when I installed 4.4.0) and it's still working.</p>
  
  <p>The code is at the end of the question; <strong>in summary</strong> what it does is start two <code>Counter</code> objects off in two child threads (these objects simply increment a variable then sleep for a bit and repeat ad infinitum - they count), the main thread waits for the user via a <code>cin.get()</code> and then interrupts both threads, waits for them to join, then outputs the result of both counters.</p>
  
  <p>Complied with 3.4.5 it runs as expected.</p>
  
  <p>Complied with 4.4.0 it runs until the user input, then dies with a message like the below - it seems the the interrupt exceptions are killing the entire process?</p>
  
  <blockquote>
    <p>terminate called after throwing an instance of '
    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    boost::thread_interrupted'</p>
    
    <p>This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.</p>
  </blockquote>
  
  <p>From what I read, I think that any (?) uncaught exception that is allowed to propagate out of a child thread will kill the process? But, I'm catching the interrupts here, aren't I? At least I <em>seem</em> to be when using 3.4.5.</p>
  
  <p>So, firstly, have I understood how interrupting works?<br>
  And, any suggestions as to what is happening and how to fix? </p>
  
  <h1>Code:</h1>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/thread/thread.hpp&gt;
  #include &lt;boost/date_time.hpp&gt;
  
  //fixes a linker error for boost threads in 4.4.0 (not needed for 3.4.5)
  //found via Google, so not sure on validity - but does fix the link error.
  extern "C" void tss_cleanup_implemented() { }
  
  class CCounter
  {
  private:
      int&amp; numberRef;
      int  step;
  public:
      CCounter(int&amp; number,int setStep) : numberRef(number) ,step(setStep) { }
  
      void operator()()
      {
          try
          {
              while( true )
              {
                  boost::posix_time::milliseconds pauseTime(50);
                  numberRef += step;
                  boost::this_thread::sleep(pauseTime);
              }
          }
          catch( boost::thread_interrupted const&amp; e )
          {
              return;
          }
      }
  };
  
  int main( int argc , char *argv[] )
  {
      try
      {
          std::cout &lt;&lt; "Starting counters in secondary threads.\n";
  
          int number0 = 0,
              number1 = 0;
          CCounter counter0(number0,1);
          CCounter counter1(number1,-1);
  
          boost::thread threadObj0(counter0);
          boost::thread threadObj1(counter1);
  
          std::cout &lt;&lt; "Press enter to stop the counters:\n";
          std::cin.get();
  
          threadObj0.interrupt();
          threadObj1.interrupt();
  
          threadObj0.join();
          threadObj1.join();
  
          std::cout &lt;&lt; "Counter stopped. Values:\n"
                    &lt;&lt; number0 &lt;&lt; '\n'
                    &lt;&lt; number1 &lt;&lt; '\n';
      }
      catch( boost::thread_interrupted&amp; e )
      {
          std::cout &lt;&lt; "\nThread Interrupted Exception caught.\n";
      }
      catch( std::exception&amp; e )
      {
          std::cout &lt;&lt; "\nstd::exception thrown.\n";
      }
      catch(...)
      {
          std::cout &lt;&lt; "\nUnexpected exception thrown.\n"
      }
  
      return EXIT_SUCCESS;
  }
  </code></pre>