[LIP] sleep function - perform activity every 10 seconds

Rohan Almeida <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Organization Sify Ltd.
Message-ID <[email protected]>
Hi,

I have a process which needs to perform an activity
every 10 seconds - starting from the 10 sec boundary.

Excuse my terminology, but this should it make it more clear.

time    activity
-----------------
12:18   process started
12:19   sleep
12:20   ACTIVITY
12:21   sleep
12:22   sleep
.....   .....
12:30   ACTIVITY


Easy to understand. Once the process starts, I get the current time.
Check if the seconds end in digit zero. If yes - perform activity.
sleep 1 second. repeat.

Then i begin to think - why should I execute sleep call every
second when i know the interval? So after first activity, I
modify the sleep interval to 10 seconds. It still works.

Questions:
* I personally prefer calling sleep every second, than doing it
   every 10 seconds. Performance wise - any issues?
* Is the sleep call accurate or does any rounding take place?
   As the 10 second boundary is imperative and not just the interval
   of 10 seconds. i.e. After a sleep call of 10 seconds, am I guaranteed
   that i will land on a 10 second boundary assuming a start at such a
   boundary and that the process needs to be run indefinitely.

I hope I'm clear enough. :-)

--
Rohan








-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.