Wait condition_variable_any
for steady_clock
by AlexGuteniev · Pull Request #4755 · microsoft/STL (original) (raw)
Fixes #4723
Turned out that:
- WinAPI
SleepConditionVariableSRW
times out using a steady clock that is not precisely synchronized withsteady_clock
implemented based onQueryPerformanceCounter
- Fixing it with
GetTickCount64()
check doesn't help, asGetTickCount64()
is also not precisely synchronized withQueryPerformanceCounter
The fix is to check exactly steady_clock
in condition_variable_any
.
This is done in a header, rather than in .cpp
for these reasons:
- The header implementation of
steady_clock::now()
is nontrivial, and resides in a non-core header, and we don't have a good core header to extract it into - Other call sites of the internal condition variable wait function check against the clock on their own already
That's why GetTickCount64()
was removed from internal wait function.
To avoid destabilizing behavior for already compiled code, I kept GetTickCount64()
on that code path (it might improve over raw SleepConditionVariableSRW
a bit).
I've inlined _Wait_for_ms_count
as to me it appeared clearer this way after these changes.