title: c++ multithreading return value
body: <p>I am using 3 threads to chunk a for loop, and the 'data' is a global array so I want to lock that part in 'calculateAll' function, </p>
  
  <pre><code> std::vector&lt; int &gt; calculateAll(int ***data,std::vector&lt;LineIndex&gt; indexList)
  {
    std::vector&lt;int&gt; v_a=std::vector&lt;int&gt;();
    for(int a=0;a&lt;indexList.size();a++)
    {         
      mylock.lock();
      v_b.push_back(/*something related with data*/); 
      mylock.unlock();
      v_a.push_back(a); 
    }
    return v_a;
  }
   for(int i=0;i&lt;3;i++)
      {
        int s =firstone+i*chunk;
        int e = ((s+chunk)&lt;indexList.size())? (s+chunk) : indexList.size();
        t[i]=std::thread(calculateAll,data,indexList,s,e);      
      }
      for (int i = 0; i &lt; 3; ++i)
      {
        t[i].join();
      }
  </code></pre>
  
  <p>my question is, how can I get the return value which is a vector from each thread and then combine them together? The reason I want to do that is because if I declare ’v_a‘ as a global vector, when each thread trys to push_back their value in this vector 'v_a' it will be some crash(or not?).So I am thinking to declare a vector for each of the thread, then combine them into a new vector for further use( like I do it without thread ).</p>
  
  <p>Or is there some better methods to deal with that concurrency problem? The order of 'v_a' does not matter.</p>
  
  <p>I appreciate for any suggestion.</p>