last day (15 days later) » 

11:08 PM
1
A: Why overflow (-2147483648) is happening in the code?

riciYou should try to avoid doing arithmetic with a mixture of signed and unsigned integer types. The results are often surprising. Clearly, timestamp is not the value you expect it to be, since timestamp/1000000 is 433430, which is considerably less than sec_since_epoch_time. Consequently, you migh...

 
Ok got it. So to fix this issue instead of using uint64_t for timestamp I should use int64_t right? So I should use like this right? int64_t timestamp = reinterpret_cast<int64_t>(current_timestamp());
 
@user1950349: You could just change the current_timestamp function to return an int64_t. But the most important thing is to make sure that current_timestamp returns the correct value, which it obviously is not.
 
I see why do you think this doesn't return the correct value. It is using chrono package to get the value? Am I using anything wrong?
 
@user1950349: second last paragraph of the answer.
 
ok, now problem is current_timestamp() is being used by lot of other methods and classes. If I directly convert uint64_t to int64_t, will that not be sufficient?
It looks like there is some weird problem with chrono package I guess. I am having some different issues as well in my other question here.
 
11:08 PM
@user1950349: That looks to me like the same problem. Did you read the paragraph in my answer?
 
yeah I read that since my background in not from C++ as I am a Java developer so having hard time. You mean to say second last paragraph?
I am stuck on this weird issue from a long time on both of my SO question. And trying to read all the tutorials of chrono library to get the idea what's wrong going on
 
What platform are you using?
 
Linux phxdbx1607 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
this is the output of uname -a
And I am running Ubuntu 14.04:
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:        14.04
Codename:       trusty
 
ok, and you're using g++ -std=c++11 ?
Where do you get the value of sec_since_epoch_time from?
 
This is what I have in CMAKEList
add_definitions( -fPIC -m64 -Wall -Wno-system-headers -Wno-deprecated -Wno-strict-aliasing  -std=c++11 -D_POSIX_PTHREAD_SEMANTICS)
That value is being passed in the code
so I printed it out
 
11:21 PM
Yes, but it must come from somewhere... you didn't just invent it.
OK, I think I was wrong about the overflow issue. I checked with a setup close to yours, and the duration is 64-bit. So the problem is that the epoch in time_since_epoch is not the same as the epoch in sec_since_epoch_time.
I'll fix the answer. Basically, in the standard C++ library, every clock has an arbitrary "epoch", which is not necessarily the host OS epoch.
 
ohhh
 
Apparently, the epoch for the system_clock (on g++/linux) is in fact the system epoch, but for steady_clock it's something like the system boot time.
 
hmm what does this mean?
 
The point is that it is clock-specific. So you can only compare clock values with values of the same clock.
 
sorry for asking stupid question
I am trying to understand basically what's wrong
yeah that I understood
 
11:28 PM
If sec_since_epoch_time didn't come from the steady_clock, then you can't rely on it having any meaning with respect to the values of steady_clock
so you have to know where sec_since_epoch_time comes from.
 
I see, I can double check that but let's say if it does come from steady_clock since that's what I am seeing it is being used everywhere in the code.
 
If it did, you wouldn't have that problem. So it doesn't.
I'm guessing it comes from system_clock.
Or from the standard C function time(0)
I updated my answer, anyway.
 
ok let me double check that
what does time(0) do?
 
type man time and you'll find out :)
"time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)."
 
yeah I just was able to lookup
so time(0) epoch is different than steady_clock epoch?
and similarly to system_clock
 
11:43 PM
some clocks, for comparison
 
I see what you are saying
all four clocks have different epoch basically
time(0) has a different epoch as compared to steady_clock and that's why this problem might be happening
if in the code we are using time(0)
right?
 
steady clock is a tricky clock, since it is not allowed to go backwards. The unix clock can go backwards because the real-time clock might drift and be recorrected from a reliable timeserver. So it makes sense that steady_clock is related to uptime, instead. It's not subject to adjustment.
Right.
 
ok that means this same problem might be with my other SO question as well right?
 
right
 
I see
tell me for steady_clock
why it has only five digitt
12710
as compared to time(0) and other clock
1437954165
 
11:47 PM
Like I said, it is probably measuring since boot
 
ohhh
 
The other ones are counting since January 1, 1970.
The C++ standard puts absolutely no requirement on epoch, other than to say that every clock has one.
Posix, on the other hand, requires that the epoch for time(0) be January 1, 1970.
But the definition of system_clock at least suggests that it will use the system epoch. If that helps you at all.
 
ok let me start digging around what else clock we are using.
In general we should use only one clock
that's all period
not mix of other clocks
 
That's the key. If you want to compare times, you must use the same clock.
 
yeah
see this
you were right
boost::chrono::steady_clock measures the time elapsed since the last boot.
What does this line mean
 
11:52 PM
RIght, that's boost. Standard C almost always provides fewer guarantees.
 
boost::chrono::steady_clock isn’t supported on all platforms. The clock is only available if the macro BOOST_CHRONO_HAS_CLOCK_STEADY is defined.
ohhh
I mixed with std chrono
yeah boost and std are different I guess but std started to grab stuff from boost
 
Normally, new library features start by being implemented in boost, which lets people experiment with them.
Then the standards committee takes a scalpel to the specification and reduces it to a useful minimum, dropping any unnecessary requirement which might artificially bind a hypothetical implementation.
It's not required that new features pass through boost, but the standards committee likes to see sample implementations rather than just theory.
 
I see
 
It looks to me like standard C++ requires steady_clock. It also requires that it never be adjusted so it can't go backwards. But it doesn't require its epoch to be boot time.
Still, that's a highly likely value.
 
yeah, I am going to scan the code and see whether I can find anywhere we are using any other clock.
 
11:56 PM
ok, dinner time. Good luck.
chao
 
ok thanks for the help
appreciated
I will provide an update once I am able to scan everything
 

last day (15 days later) »