Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » Bugs (& fixes) » A strange bug in std::chrono
A strange bug in std::chrono [message #57440] Fri, 13 August 2021 03:16 Go to next message
chivstyle is currently offline  chivstyle
Messages: 8
Registered: August 2020
Location: China
Promising Member
upp:15935
os: Windows 10 64 bits, ver: 10.0.19042.985

I used std::chrono::high_resolution_clock to calculate time interval, like below:

double ts = 0;
auto t1 = std::chrono::high_resolution_clock::now();
do_something();
auto t2 = std::chrono::high_resolution_clock::now();
ts += std::chrono::duration<double>(t2 - t1).count();


The value of ts will be minus. I attached an example to demonstrate this bug, please check it out.
(complie it: clang++ -o chrono_test chrono_test.cpp)

If it catched this bug, the app will exit at once.
q_count = 1101145088, q_rate = 799.75
q_count = 1101146112, q_rate = 799.75
q_count = 1101147136, q_rate = 799.75
q_count = 1101148160, q_rate = 799.75
q_count = 1101149184, q_rate = 799.75
q_count = 1101150208, q_rate = 799.75
q_count = 1101151232, q_rate = 799.75
q_count = 1101152256, q_rate = 799.75
q_count = 1101153280, q_rate = -2150.39
catched that bug, hahaha


Of course, I compiled this program with gcc, and clang from latest msys2. It worked well. So I think it's a bug.
Re: A strange bug in std::chrono [message #57441 is a reply to message #57440] Fri, 13 August 2021 03:28 Go to previous message
chivstyle is currently offline  chivstyle
Messages: 8
Registered: August 2020
Location: China
Promising Member
I'm so sorry to post topic here without reading the regulations. I didn't find the way to remove it.
Previous Topic: strange situation in the ide with package that hasn't opened anymore.
Next Topic: GetSystemInfo - board_serial issue on build 16270
Goto Forum:
  


Current Time: Thu Nov 14 05:03:56 CET 2024

Total time taken to generate the page: 0.02736 seconds