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
In reply to Re: missing second of time
by afoken
in thread missing second of time
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |