title: main terminating a thread with infinite loop
body: <p>I'm quite new with multi-threading. Below is an example code I was trying to run. Please forgive syntax errors (if any), as I'm going by memory.<br>
  The issue with the code below is that it terminates immediately, whereas it should be running forever. I wanted to know why the main is calling the deconstructor, even though there is a <code>while (true)</code> statement.   </p>
  
  <p>There are no other classes, so it is not due to interactions with others. The only thing the main does is to create an object of type myclass, and call function1() below. </p>
  
  <pre><code>    int main()
      {
          myclass Object;
          Object.function1();
  
          return 0;
      }
  
      /**** new file   ******/
      typedef boost::shared_ptr&lt;boost::thread&gt; thread_pointer;
  
      class myclass
      {
      public:
          // some stuff
          void function1();
      private:
          // some stuff
          void myfunction();
          thread_pointer tr_ptr;  
      };
  
      ~myclass() {
          tr_ptr-&gt;join();
      }
  
      void myclass::function1()
      {
          // some stuff   
          tr_ptr = thread_ptr(new boost::thread(&amp;myclass::myfunction, this));  
  
      }
  
      void myclass::myfunction()
      {
          // some stuff
          while(true){
               // some stuff
          } 
      }
  </code></pre>