Skip to content
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

<__msvc_chrono.hpp>: Use _Xtime_get_ticks in _To_timespec64_sys_10_day_clamped for consistency #3681

Merged

Conversation

statementreply
Copy link
Contributor

@statementreply statementreply commented May 2, 2023

Part of #1588.

_Xtime_get_ticks and system_clock::now would no longer be equal after a future leap second when #1520 is eventually fixed. This PR changes the clock used in _To_timespec64_sys_10_day_clamped to be consistent with code that consumes its result, e.g. target in

STL/stl/src/cond.cpp

Lines 72 to 80 in 091cad2

_timespec64 now;
_Timespec64_get_sys(&now);
_Mtx_clear_owner(mtx);
if (!cond->_get_cv()->wait_for(cs, _Xtime_diff_to_millis2(target, &now))) { // report timeout
_Timespec64_get_sys(&now);
if (_Xtime_diff_to_millis2(target, &now) == 0) {
res = _Thrd_timedout;
}
}

@BillyONeal pointed out (on Discord) that this PR could break (already somewhat broken) timed wait ABI:

_To_xtime_10_day_clamped, used by condition_variable::wait_for, this_thread::sleep_for, etc., calls system_clock::now() internally to compute a value interpreted as GetSystemTimeAsFileTime + offset by another component. My understanding is that if the linker picks the old version of _To_xtime_10_day_clamped and the new version of system_clock::now() from different object files, all those wait functions could wait for a few seconds too short (assuming positive leap seconds) after future leap seconds.

@statementreply statementreply requested a review from a team as a code owner May 2, 2023 08:03
@StephanTLavavej StephanTLavavej added bug Something isn't working chrono C++20 chrono labels May 3, 2023
@StephanTLavavej
Copy link
Member

Looks good to me - no behavioral change now, and the consistency argument for the future is convincing. Thanks!

@StephanTLavavej StephanTLavavej removed their assignment May 12, 2023
@StephanTLavavej StephanTLavavej added enhancement Something can be improved and removed bug Something isn't working labels May 12, 2023
@StephanTLavavej StephanTLavavej self-assigned this May 17, 2023
@StephanTLavavej
Copy link
Member

I'm speculatively mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@CaseyCarter CaseyCarter merged commit 04db120 into microsoft:main May 18, 2023
@CaseyCarter
Copy link
Member

Thanks for fixing this future bug before we could write it! 🕦 🕐 🕙 🕥 🕚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chrono C++20 chrono enhancement Something can be improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants