Public bug reported:

When I compile and run the attached program, the output shows an
inconsistency between the time returned by clock_gettime() and time().
Even though the call to time() is after the call to clock_gettime(), it
can return an earlier timestamp. This is particularly apparent after
waiting until a particular time, as shown in the example code. Sample
output is:

Now (clock_gettime) time is 1574670740847614452 (timespec)
=>1574670740(time_t)
=>8:32:20
Now (time(nullptr)) time is 1574670740(time_t)
=>8:32:20
Now (clock_gettime) time is 1574670742000185727 (timespec)
=>1574670742(time_t)
=>8:32:22
Now (time(nullptr)) time is 1574670741(time_t)
=>8:32:21

Compiled with g++ v7 from the ubuntu repositories. Output of g++
version:

g++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: linux-image-4.15.0-1064-oem 4.15.0-1064.73
ProcVersionSignature: Ubuntu 4.15.0-1064.73-oem 4.15.18
Uname: Linux 4.15.0-1064-oem x86_64
ApportVersion: 2.20.9-0ubuntu7.9
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Mon Nov 25 08:28:21 2019
DistributionChannelDescriptor:
 # This is the distribution channel descriptor for the OEM CDs
 # For more information see http://wiki.ubuntu.com/DistributionChannelDescriptor
 canonical-oem-somerville-bionic-amd64-20180608-47+beaver-turtlebay+X57
InstallationDate: Installed on 2019-08-12 (104 days ago)
InstallationMedia: Ubuntu 18.04 "Bionic" - Build amd64 LIVE Binary 
20180608-09:38
ProcEnviron:
 TERM=xterm-256color
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_GB.UTF-8
 SHELL=/bin/bash
SourcePackage: linux-signed-oem
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: linux-signed-oem (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug bionic

** Attachment added: "File showing inconsistency"
   https://bugs.launchpad.net/bugs/1853807/+attachment/5307635/+files/t2.cpp

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1853807

Title:
  clock_gettime and time are inconsistent with each other

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux-signed-oem/+bug/1853807/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to