title: C++ Loop with fixed delta time on a background Thread
body: <p>The goal is to call a function on a background thread with a fixed delta Time.</p>
  
  <p>The function should get called 60 times / second, hence at timestamps 0, 0.0166, etc. The timestamps should be hit as precisely as possible.</p>
  
  <p>The simple but probably not best solution would be to run a while(true)-loop and let the thread sleep until the next time the function should be called. Here's half C++ / half pseudo-Code how it'd do it.</p>
  
  <pre><code>float fixedDeltaTime = 1.0 / 60.0;
  void loopFunction() 
  {
        while(true)
        {
           auto currentTime = getTime();
           // do work
           auto timePassed = getTime() - currentTime;
           int times = (timePassed / fixedDeltaTime);
           sleep(  (fixedDeltaTime * times) - timePassed)
        }
  }
  
  int main()
  {
     std::thread loopFunction(call_from_thread);
     return 0;
  }
  </code></pre>
  
  <p>Is there a better solution than this and would this even work?</p>