4 ms·
Naive question: Would a reasonable way to avoid this scenario be, to increment a secondary counter when the primary counter reaches max-1, then reset the primar
by nmg 8y ago
Naive question: Would a reasonable way to avoid this scenario be, to increment a secondary counter when the primary counter reaches max-1, then reset the primary counter to zero?
- sbradford26 8y agoA couple different ways to avoid the issue: 1: Size the type used to store the value so that it cannot overflow even in corner cases such as a plane being on for several months. Ex. going from a 32 bit int to a 64 bit. 2: Have a flag that you set when the counter overflows, so you can calculate the actual time. Given the length of time that planes are on this would give you enough time. 3:Lessen the precision of the counter (Probably not an option since the precision is usually a requirement)
- ascar 8y agoThis is mathematically no different than using a larger int. Your second counter would store the more significant bits.
- lucb1e 8y agoWhat if the secondary counter overflows? And should all software now check two counters when they want to know the actual time? Just use a 64 bit integer, at least for this purpose (since this apparently needs only 10ms precision): that is twice as large as a normal integer, so basically the same as using two counters, except you don't need extra logic in your code.
- x0x0 8y agoProlly process. IE a global review of every counter in the code, and again for each commit, of the max run time encountered by any code. Plus also prolly running in sim with eg 1 million x time.