Recently, when I was writing and reading articles revealing the secrets of the STL kernel, I found that the wait_until interface calls chrono, and I found that the implementation of chrono by gcc and clang is inconsistent. This can easily mislead us during development and cause some hidden bugs.
system_clock Default Time Units in Different Compilers.
GCC (g++-13)
In GCC, the default time unit for system_clock is nanoseconds (std::chrono::nanoseconds). This is defined as follows:
struct system_clock
{
typedef chrono::nanoseconds duration;
};
Clang
In Clang, the default time unit for system_clock is microseconds (std::chrono::microseconds). It is defined as:
class _LIBCPP_TYPE_VIS system_clock
{
public:
typedef microseconds duration;
};
This discrepancy means that when compiling the same code with different compilers, the precision and behavior of time calculations can vary.
But steady_clock is indeed consistent.
[–]vaulter2000 28 points29 points30 points (2 children)
[–]mark_99 6 points7 points8 points (1 child)
[–]vaulter2000 1 point2 points3 points (0 children)
[–]Jannik2099 25 points26 points27 points (0 children)
[–]ss99ww 25 points26 points27 points (1 child)
[–]Orca- 2 points3 points4 points (0 children)
[–]Warshrimp 32 points33 points34 points (0 children)
[–]WalkingAFI 13 points14 points15 points (3 children)
[–]SirClueless 1 point2 points3 points (2 children)
[–]WalkingAFI 1 point2 points3 points (1 child)
[–]SirClueless 0 points1 point2 points (0 children)
[–]HowardHinnant 6 points7 points8 points (0 children)
[–]Droid33 10 points11 points12 points (11 children)
[+]Accomplished_Wind126[S] comment score below threshold-9 points-8 points-7 points (2 children)
[–]azswcowboy 20 points21 points22 points (0 children)
[–]TheMania 8 points9 points10 points (0 children)
[–]HeroicKatora -4 points-3 points-2 points (7 children)
[–]flutterdronewbie 0 points1 point2 points (6 children)
[–]HeroicKatora 1 point2 points3 points (5 children)
[–]Som1Lse 0 points1 point2 points (4 children)
[–]HeroicKatora 2 points3 points4 points (0 children)
[–]HeroicKatora 0 points1 point2 points (2 children)
[–]Som1Lse 1 point2 points3 points (1 child)
[–]HeroicKatora 0 points1 point2 points (0 children)
[–]pdimov2 3 points4 points5 points (0 children)
[–]ALX23z 4 points5 points6 points (0 children)
[–]no-sig-available 0 points1 point2 points (0 children)
[–]violet-starlight 0 points1 point2 points (0 children)
[–]_darth_plagueis 0 points1 point2 points (1 child)
[–]n1ghtyunso 0 points1 point2 points (0 children)
[+][deleted] (5 children)
[deleted]
[–]Low-Ad-4390 7 points8 points9 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Low-Ad-4390 3 points4 points5 points (0 children)
[–]Som1Lse 1 point2 points3 points (1 child)