Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: missing second of time

by afoken (Chancellor)
on Jan 25, 2020 at 19:03 UTC ( [id://11111888]=note: print w/replies, xml ) Need Help??


in reply to missing second of time

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". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11111888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found