title: dynamic thread creation using std::thread in c++
body: <p>How we can Create dynamic threads using std::thread. Actually I am accessing some raw string from a queue and have to perform some processing on that and the queue is having thousands of such messages, so i want to create a thread for each message to improve the performance. I can create the thread's using below code.</p>
  
  <pre><code>unsigned int n = std::thread::hardware_concurrency();
  std::thread myThreads[n];
  while(true)
  {
  
  
      for (int i=0; i&lt;n; i++){
          myThreads[i] = std::thread(&amp;ControlQueue::processSomeStuff,this,msg_struct);
          }
  
  
  
  //for joining
  for (int i=0; i&lt;n; i++){
      myThreads[i].join();
  }
  }
  </code></pre>
  
  <p>but the thing is if I use the above code then it will create the threads only for que.size() 
  threads, but the queue will have some more new messages.</p>
  
  <p>So is there any method for creating a thread for each new message dynamically. like server socket creates a new socket for processing the client request.</p>