title: (simple) boost thread_group question
body: <p>I'm trying to write a fairly simple threaded application, but am new to boost's thread library. A simple test program I'm working on is:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/thread.hpp&gt;
  
  int result = 0;
  boost::mutex result_mutex;
  
  boost::thread_group g;
  
  void threaded_function(int i)
  {
      for(; i &lt; 100000; ++i) {}
  
      {
          boost::mutex::scoped_lock lock(result_mutex);
          result += i;
      }
  }
  
  int main(int argc, char* argv[])
  {
      using namespace std;
  
      // launch three threads
      boost::thread t1(threaded_function, 10);
      boost::thread t2(threaded_function, 10);
      boost::thread t3(threaded_function, 10);
  
      g.add_thread(&amp;t1);
      g.add_thread(&amp;t2);
      g.add_thread(&amp;t3);
  
      // wait for them
      g.join_all();
  
      cout &lt;&lt; result &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  
  <p>However, when I compile and run this program I get an output of </p>
  
  <pre><code>$ ./test 
  300000
  test: pthread_mutex_lock.c:87: __pthread_mutex_lock: Assertion `mutex-&gt;__data.__owner == 0' failed.
  Aborted
  </code></pre>
  
  <p>Obviously, the result is correct but I'm worried about this error message, especially because the real program, which has essentially the same structure, is getting stuck at the join_all() point. Can someone explain to me what is happening? Is there a better way to do this, i.e. launch a number of threads, store them in a external container, and then wait for them all to complete before continuing the program? </p>
  
  <p>Thanks for your help.</p>