[C++] Run codes for only 60 times each second.
- by djzmo
Hello there,
I'm creating a directx application that relies on the system time (because it must be accurate),
and I need to run lines of code for 60 times each second in the background (in a thread created by boost::thread). that's equal to 60 FPS (frame per second), but without depending on the main application frame rate.
//.................
void frameThread()
{
// I want to run codes inside this loop for *exactly* 60 times in a second.
// In other words, every 16.67 (1000/60) milliseconds
for(;;)
{
DoWork();
//.........
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
initialize();
//.....stuffs
boost::thread framethread(frameThread);
//......
}
Is there a way to do this?
Any kind of help would be appreciated :)