-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows: sleep_for is dependent on system clock #609
Comments
Sure. I prefer it the be implemented in the details/os.h file for obvoius reasons |
joaomoreno
added a commit
to joaomoreno/spdlog
that referenced
this issue
Jan 11, 2018
joaomoreno
added a commit
to joaomoreno/spdlog
that referenced
this issue
Jan 11, 2018
bachittle
pushed a commit
to bachittle/spdlog
that referenced
this issue
Dec 22, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there! 👋
We've hit this issue in VS Code: microsoft/vscode#41136
Ultimately here's the problem:
std::this_thread::sleep_for
is poorly implemented in Windows and depends on the system clock. When the thread is sleeping and the system clock is changed to a previous time, the sleep takes longer than expected, apparently by as much as the system clock was changed.The bug easily reproduces with this snippet:
Simply go back in time and one of the 500ms
sleep_for
calls will take much longer.I found a comment in here which indicates that
sleep_until
doesn't have the same issue, though I don't really verify that. I tried using bothsystem_clock
andsteady_clock
to compute thesleep_until
argument; the bug still happens.Of course, using the WinAPI call
Sleep
works like a charm.Would you accept a PR in which I replace
sleep_for
calls forSleep
calls in Windows?The text was updated successfully, but these errors were encountered: