Relative Content

Tag Archive for c++windows-subsystem-for-linuxc++-chronodriftubuntu-24.04

std::chrono now() induces very significant drift with Ubuntu 24.04 under WSL2

I’ve got an algorithm I’ve used for years to emulate a real-time clock in a non-real-time environment. It’s always worked exceptionally well until used on Ubuntu 24.04 in WSL2 in Windows 11. The logic predicts in system clock time when each next time-step should occur and repeatedly calls chrono’s now() in a loop until that point in time is reached, then continues with execution of the next frame. When set up in this environment, now()’s return value will occasionally jump a significant amount forward in time (e.g., ~25 seconds) between successive calls. Simply observing the application run reveals that its not a matter of now() taking ~25 seconds to return a value as the whole app will complete in ~5 seconds when it should have taken ~30. The implication is that calling now() has actually altered the clock’s time. To verify this, I wrapped my sample code in a bash script where I could monitor and resync WSL’s clock … now() is indeed altering the clock’s time.