clock_gettime and time are inconsistent with each other

Bug #1853807 reported by Anthony Williams
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux-signed-oem (Ubuntu)
New
Undecided
Unassigned

Bug Description

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)

Revision history for this message
Anthony Williams (anthony-justsoftwaresolutions) wrote :
Revision history for this message
Anthony Williams (anthony-justsoftwaresolutions) wrote :

This bug also occurs on Fedora.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.