public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug time/30200] New: time sometimes appears to go backwards
@ 2023-03-05 17:21 bruno at clisp dot org
  2023-03-05 17:22 ` [Bug time/30200] " bruno at clisp dot org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: bruno at clisp dot org @ 2023-03-05 17:21 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30200

            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=14731&action=edit
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 § 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 § 7.29.2.5 says
  "The time function returns the implementation’s best approximation to
   the current calendar time."
and POSIX
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/time.html>
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 = { tv_sec = 1678035679, tv_nsec = 343581 }
tt2            = 1678035678
Aborted
ts1 = { tv_sec = 1678035679, tv_nsec = 1099393 }
tt2            = 1678035678
Aborted
ts1 = { tv_sec = 1678035679, tv_nsec = 2502625 }
tt2            = 1678035678
Aborted
ts1 = { tv_sec = 1678035680, tv_nsec = 601354 }
tt2            = 1678035679
Aborted
ts1 = { tv_sec = 1678035680, tv_nsec = 1543640 }
tt2            = 1678035679
Aborted
ts1 = { tv_sec = 1678035680, tv_nsec = 2320893 }
tt2            = 1678035679
Aborted
ts1 = { tv_sec = 1678035681, tv_nsec = 630264 }
tt2            = 1678035680
Aborted
ts1 = { tv_sec = 1678035681, tv_nsec = 1556696 }
tt2            = 1678035680
Aborted
ts1 = { tv_sec = 1678035681, tv_nsec = 2380812 }
tt2            = 1678035680
Aborted
ts1 = { tv_sec = 1678035682, tv_nsec = 806262 }
tt2            = 1678035681
Aborted
ts1 = { tv_sec = 1678035682, tv_nsec = 1696936 }
tt2            = 1678035681
Aborted
ts1 = { tv_sec = 1678035682, tv_nsec = 2484177 }
tt2            = 1678035681
Aborted
ts1 = { tv_sec = 1678035683, tv_nsec = 242097 }
tt2            = 1678035682
Aborted
ts1 = { tv_sec = 1678035683, tv_nsec = 972766 }
tt2            = 1678035682
Aborted
ts1 = { tv_sec = 1678035683, tv_nsec = 1801143 }
tt2            = 1678035682
Aborted
ts1 = { tv_sec = 1678035684, tv_nsec = 221852 }
tt2            = 1678035683
Aborted
ts1 = { tv_sec = 1678035684, tv_nsec = 1041359 }
tt2            = 1678035683
Aborted
ts1 = { tv_sec = 1678035684, tv_nsec = 1822872 }
tt2            = 1678035683
Aborted

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-03-21 20:41 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-05 17:21 [Bug time/30200] New: time sometimes appears to go backwards bruno at clisp dot org
2023-03-05 17:22 ` [Bug time/30200] " bruno at clisp dot org
2023-03-05 17:23 ` bruno at clisp dot org
2023-03-05 17:55 ` girish946 at gmail dot com
2023-03-05 18:28 ` schwab@linux-m68k.org
2023-03-05 18:58 ` schwab@linux-m68k.org
2023-03-05 19:04 ` bruno at clisp dot org
2023-03-06 12:15 ` adhemerval.zanella at linaro dot org
2023-03-06 12:25 ` fweimer at redhat dot com
2023-03-06 12:45 ` bruno at clisp dot org
2023-03-06 13:08 ` adhemerval.zanella at linaro dot org
2023-03-06 13:14 ` fweimer at redhat dot com
2023-03-19 23:43 ` eggert at cs dot ucla.edu
2023-03-21  4:18 ` sam at gentoo dot org
2023-03-21 15:06 ` adhemerval.zanella at linaro dot org
2023-03-21 15:29 ` bruno at clisp dot org
2023-03-21 16:02 ` adhemerval.zanella at linaro dot org
2023-03-21 20:00 ` bruno at clisp dot org
2023-03-21 20:03 ` adhemerval.zanella at linaro dot org
2023-03-21 20:25 ` fw at deneb dot enyo.de
2023-03-21 20:41 ` adhemerval.zanella at linaro dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).