boostorg/fiber

Can I adjust the accuracy of timer?

Opened this issue · 0 comments

zhmt commented

Failed to achieve FPS 60 ( frame per second) :

auto timenow() {
  return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

int main() {
  boost::fibers::fiber mainFiber([]() 
    {
      while (true) {
        auto now = timenow();
        boost::this_fiber::sleep_for(std::chrono::milliseconds(16));
        std::cout << timenow() - now << "\n";
      }
    });
  mainFiber.join();
}

Outputs ( should be 16 ):

34
27
30
31
31
31
30
31
30
29