clock_gettime and time are inconsistent with each other
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(
=>8:32:20
Now (time(nullptr)) time is 1574670740(time_t)
=>8:32:20
Now (clock_gettime) time is 1574670742000185727 (timespec)
=>1574670742(
=>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~
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-
ProcVersionSign
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
DistributionCha
# This is the distribution channel descriptor for the OEM CDs
# For more information see http://
canonical-
InstallationDate: Installed on 2019-08-12 (104 days ago)
InstallationMedia: Ubuntu 18.04 "Bionic" - Build amd64 LIVE Binary 20180608-09:38
ProcEnviron:
TERM=xterm-
PATH=(custom, no user)
XDG_RUNTIME_
LANG=en_GB.UTF-8
SHELL=/bin/bash
SourcePackage: linux-signed-oem
UpgradeStatus: No upgrade log present (probably fresh install)
This bug also occurs on Fedora.