Perl Monk, Perl Meditation | |
PerlMonks |
Re: missing second of timeby afoken (Chancellor) |
on Jan 25, 2020 at 19:03 UTC ( [id://11111888]=note: print w/replies, xml ) | Need Help?? |
First, sleep(), like any other system call, can be interrupted at any time. (Beancounting: Yes, sleep() is technically no system call, but it uses system calls.) That means that sleep(1) may actually return after just a few milliseconds. See also Signal to a sleeping Perl program. Second, at any system call, you are returning control back to the operating system. And unless you run a real-time operating system, there are NO guarantees for when you get back control. Most times, it happens within milliseconds. But under heavy load, the operating system may decide that your process has to wait, and so you may get delays in the seconds range from start to end of a system call, and you will see jumps of several seconds. Third, even without system calls, your programm will be forcefully interrupted and control returns forcefully to the operating system - unless you are running a real time operating system. Fourth, if you need more or less exactly 1.000 s between function calls, don't use a function that has only 1 s resolution for timing. You want at least millisecond resolution. See previous postings by other monks.
So if you have hard real-time requirements, either use a real-time operating system, or run the timing-critical part on bare metal (e.g. on a microcontroller). See Re^2: Assembly language and Re^14: CPAN failed install for details. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
In Section
Seekers of Perl Wisdom
|
|