title: Thread management in a game loop?
body: <p>I am in the middle of developing a game and came across the problem of multithreading. I already used multithreading successfully when loading resources. I did that by creating some threads at some point, assigned them functions, and waited for them to finish, while drawing a loading screen, pretty straightforward.</p>
  
  <p>Now I want to create some threads, that can wait idle till they receive a function, when they do, solve that, then stay idle again. They must operate in a game loop, which is roughly like this (I came up with these function names just for easy visualization):</p>
  
  <pre><code>std::thread t0,t1;
  while(gamerunning)
  {
     UpdateGame();
     t0.receiveFunc( RenderShadow );
     t1.receiveFunc( RenderScene );
     WaitForThreadstoFinishWork();
     RenderEverything(); //Only draw everything if the threads finished (D3D11's Deferred Context rendering)
  }
  t0.Destroy();
  t1.Destroy();
  </code></pre>
  
  <p>My rendering engine is working, and for the time being (for testing), I created threads in my game loop, which is a terrible way of even a quick test, because my rendering speed even slowed down. By the way, I am using C++11's  library. </p>
  
  <p>Long story short, I want to create threads before my game loop takes place, and use those in the game loop afterwards, hope someone can help me out. If it is an option, I would really want to stay away from the lower levels of threading, I just need the most straightforward way of doing this.</p>