Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

clock_gettime suddenly not working anymore today, what could be the issue?

My code suddenly not working anymore today, what could be the issue?
Here is the part of the code.

struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
int32_t tnow = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;

if (tnow - decoder->last_dumped >= 300) {
    decoder->last_dumped = tnow;
    // it was working before
    ...
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

tv_sec is a signed integer holding seconds, so 1000 * tv_sec will overflow an int32_t. Use int64_t.

Overflow will occur after (1 << 31) milliseconds, which is about 24.8 days.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading