You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WinAPI SleepConditionVariableSRW times out using a steady clock that is not precisely synchronized with steady_clock implemented based on QueryPerformanceCounter
Fixing it with GetTickCount64() check doesn't help, as GetTickCount64() is also not precisely synchronized with QueryPerformanceCounter
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.
Thanks! I pushed a conflict-free merge with main and a simple transformation. This fix makes sense and I verified that the affected libcxx tests pass 10 times in a row. 😻
I also fixed the title, because the correctness fix is specific to condition_variable_any; the impact on condition_variable is a minor performance improvement due to not having to call GetTickCount64() anymore.
_Cnd_timedwait_for_unchecked is missing _CRTIMP2_PURE, forcing static linkage always. This is problematic, since the function is missing from the DLL version of the runtime library.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4723
Turned out that:
SleepConditionVariableSRW
times out using a steady clock that is not precisely synchronized withsteady_clock
implemented based onQueryPerformanceCounter
GetTickCount64()
check doesn't help, asGetTickCount64()
is also not precisely synchronized withQueryPerformanceCounter
The fix is to check exactly
steady_clock
incondition_variable_any
.This is done in a header, rather than in
.cpp
for these reasons:steady_clock::now()
is nontrivial, and resides in a non-core header, and we don't have a good core header to extract it intoThat'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 rawSleepConditionVariableSRW
a bit).I've inlined
_Wait_for_ms_count
as to me it appeared clearer this way after these changes.