Hi Johannes,
El 18/02/18 a las 12:01, Johannes Kliemann escribió:
Hi all,
I noticed a 32 bit overflow in the Timer::Connection sleep functions and triggers. Calling usleep or trigger_once with an hour (3 600 000 000 us) works but calling it with two hours (7 200 000 000 us) causes something to overflow and stop the timer after 2 905 032 704 us which equals 7 200 000 000 & (2^32 - 1).
As far as I have checked this these functions use the unsigned long which is indeed 64 bit but I think at some point only 32 bit are used.
Is this intended behaviour? If so I think it would make sense to give out a warning at least.
I printed sizeof(unsigned) (Timer::Connection::usleep takes unsigned), and it says 4. Therefore, it seems natural to me that you can't input numbers greater than 71 minutes and 34 seconds which are approximately 2^32 us. For greater timeouts you could use msleep(unsigned) (up to 49 days and 17 hours). The best way, however, would be to use the higher-level Timeout framework (see Timer::Periodic_timeout and Timer::One_shot_timeout). Admittedly, we try to get rid of directly using the Timer::Connection entirely. The new framework is safer and adds features like scheduling one timer session among multiple timeouts. By now, it doesn't support timeouts greater than 71 minutes and 34 seconds but it is on my TODO list to fix this soon.
Cheers, Martin