From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A8DC03858D32; Sun, 5 Mar 2023 17:21:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8DC03858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678036876; bh=FiuPJ/vecwXAkt1qoUSd0AqpRs/GaVrSa+UZbS0lY4g=; h=From:To:Subject:Date:From; b=goi9JxOdEu2WnIlZZFBBpWqM4VoSL1U7NtgIIYr/x1Wx9a9QZVZZpe0FY4BG2ls4B /d28XSuGvqRTgU57G7QUS0up1tYplRLkSKLUUjbt8+4bheZksqlqihHoaBRY2tYeab LgH0zmflBFtXj61xjMrgNQTMC0zhJpeKjxJponso= From: "bruno at clisp dot org" To: glibc-bugs@sourceware.org Subject: [Bug time/30200] New: time sometimes appears to go backwards Date: Sun, 05 Mar 2023 17:21:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: time X-Bugzilla-Version: 2.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bruno at clisp dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30200 Bug ID: 30200 Summary: time sometimes appears to go backwards Product: glibc Version: 2.35 Status: UNCONFIRMED Severity: normal Priority: P2 Component: time Assignee: unassigned at sourceware dot org Reporter: bruno at clisp dot org Target Milestone: --- Created attachment 14731 --> https://sourceware.org/bugzilla/attachment.cgi?id=3D14731&action=3Ded= it test program The attached test program invokes first timespec_get, and then time(NULL). With a small probability (ca. 0.1% to 0.3%), the second call returns a seconds value that is smaller than the one from the first call. Since ISO C23 =C2=A7 7.29.2.6 says "If base is TIME_UTC , the tv_sec member is set to the number of seconds since an implementation-defined epoch, truncated to a whole value and the tv_nsec member is set to the integral number of nanoseconds, rounded to the resolution of the system clock." and ISO C23 =C2=A7 7.29.2.5 says "The time function returns the implementation=E2=80=99s best approximatio= n to the current calendar time." and POSIX says "The time() function shall return the value of time in seconds since the Epoch." my expectation is that - both ts1.tv_sec and tt2 denote seconds since the epoch, - tt2 is not smaller than ts1.tv_sec (because if it were, tt2+1 would be a better approximation to the current time than tt2). The test program, however, reports ts1.tv_sec > tt2 around 12 to 40 times in 10000 runs. How to reproduce: $ gcc -Wall -g -O2 foo.c $ for i in `seq 10000`; do ./a.out ; done Example output: ts1 =3D { tv_sec =3D 1678035679, tv_nsec =3D 343581 } tt2 =3D 1678035678 Aborted ts1 =3D { tv_sec =3D 1678035679, tv_nsec =3D 1099393 } tt2 =3D 1678035678 Aborted ts1 =3D { tv_sec =3D 1678035679, tv_nsec =3D 2502625 } tt2 =3D 1678035678 Aborted ts1 =3D { tv_sec =3D 1678035680, tv_nsec =3D 601354 } tt2 =3D 1678035679 Aborted ts1 =3D { tv_sec =3D 1678035680, tv_nsec =3D 1543640 } tt2 =3D 1678035679 Aborted ts1 =3D { tv_sec =3D 1678035680, tv_nsec =3D 2320893 } tt2 =3D 1678035679 Aborted ts1 =3D { tv_sec =3D 1678035681, tv_nsec =3D 630264 } tt2 =3D 1678035680 Aborted ts1 =3D { tv_sec =3D 1678035681, tv_nsec =3D 1556696 } tt2 =3D 1678035680 Aborted ts1 =3D { tv_sec =3D 1678035681, tv_nsec =3D 2380812 } tt2 =3D 1678035680 Aborted ts1 =3D { tv_sec =3D 1678035682, tv_nsec =3D 806262 } tt2 =3D 1678035681 Aborted ts1 =3D { tv_sec =3D 1678035682, tv_nsec =3D 1696936 } tt2 =3D 1678035681 Aborted ts1 =3D { tv_sec =3D 1678035682, tv_nsec =3D 2484177 } tt2 =3D 1678035681 Aborted ts1 =3D { tv_sec =3D 1678035683, tv_nsec =3D 242097 } tt2 =3D 1678035682 Aborted ts1 =3D { tv_sec =3D 1678035683, tv_nsec =3D 972766 } tt2 =3D 1678035682 Aborted ts1 =3D { tv_sec =3D 1678035683, tv_nsec =3D 1801143 } tt2 =3D 1678035682 Aborted ts1 =3D { tv_sec =3D 1678035684, tv_nsec =3D 221852 } tt2 =3D 1678035683 Aborted ts1 =3D { tv_sec =3D 1678035684, tv_nsec =3D 1041359 } tt2 =3D 1678035683 Aborted ts1 =3D { tv_sec =3D 1678035684, tv_nsec =3D 1822872 } tt2 =3D 1678035683 Aborted --=20 You are receiving this mail because: You are on the CC list for the bug.=