I implemented a very simple task scheduler using std::condition_variable and it works fine on Ubuntu Linux without any noticeable delays: when I schedule a task to trigger in 500ms it is actually triggered in almost exactly 500ms.
But on Windows it is a different story: when I schedule a task to trigger in 500ms it is triggered somewhere in the range from ~503ms to ~515ms, "lagging" by ~10ms on average. And it seems to "lag" for this 10ms regardless of the time the task is actually scheduled (1000ms, 500ms, 200ms, whatever).
I know that it is actually fine that wait_until and any sleep functions "lag" a little (it sleeps for a little more than specified in the parameter), but 10ms seems kinda rough, especially when you schedule your task to go off in, say, 50ms.
The code is available by this link.
Do you know why does this happen? Is it possible to improve the situation?
- On my Ubuntu 20.04 Linux I use
c++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 - On my Windows 10 I use MinGW x64 7.2.0 (upgrading to MinGW x64 9.2.0 didn't help)
I don't really believe it is the compiler versioning issue, though.