title: How can let a C++11 thread run several different functions?
body: <p>I am learning the new multi-threading techniques in C++11. Almost all the tutorials I read on the web is teaching how to launch a new thread(or several threads) executing a function, how to join (or detach) the thread(or threads) later and how to avoid racing conditions using <code>mutex</code>, etc. </p>
  
  <p>But I don't see any of them showing how to make a thread execute several functions at different parts of the program. The question is, with C++11 threads, is it possible to achieve the following? If so, how? (Giving an example will be great).</p>
  
  <pre><code>void func1(std::vector&lt;int&gt; &amp; data1){ ... }
  
  void func2(std::vector&lt;int&gt; &amp; data2){ ... }
  
  //  main function version I
  int main(){
     std::vector&lt;int&gt; data1; 
     // prepare data1 for func1;
     std::thread t1(func1, std::ref(data1));
  
     std::vector&lt;int&gt; data2; 
     // prepare data2 for func2;
     if (func1 in t1 is done){ 
           t1(func2, std::ref(data2)); 
     }
  
     t1.join();
     return 0;      
  }
  </code></pre>
  
  <p>And further, what if I want to put the the above <code>main</code> function body into a loop, as following. Is it possible? If so, how? </p>
  
  <pre><code>//main function version II
  int main(){
     std::vector&lt;int&gt; bigdata1;
     std::vector&lt;int&gt; bigdata2;
  
     std::thread t1; // Can I do this without telling t1 the function 
                     // to be executed?
  
     for(int i=0; i&lt;10; ++i){
         // main thread prepare small chunk smalldata1 from bigdata1 for func1;
  
         if(t1 is ready to execute a function){t1(func1, std::ref(smalldata1));}
  
         // main thread do other stuff, and prepare small chunk smalldata2 from bigdata2 for func2;
  
         if (func1 in t1 is done){ 
              t1(func2, std::ref(smalldata2)); 
         }
     }
  
     t1.join();
     return 0;      
  }
  </code></pre>