George <ge*********@yahoo.com> wrote:
I have created a program that sends msgs at certain rate. What is the
best way to do this so that I get a consistent rate all the time?
For example I want to send 5000 msgs per second, and 1000 msgs per
second.
I have used "usleep" and most of the time I get way less than what I
expect mainly do to system interrupt.
There are a lot of problems here. First of all, there's no solution
from a standard C point of view - the standard does not make any
promises about the execution speed of a program etc. But even if
you resort to (non-standard) extensions like the use of usleep()
achieving what you want to do might be impossible because, unless
you have a real-time (or a single-user, single-tasking) operating
system there are typically hardly any ways that guarantee a reliable
timing.
<OT>
Take for example usleep(). On the systems I know it to exist it puts
the process to sleep and just guarantees that the process won't get
woken up before the time passed as the argument is over - but there
is no implicit promise that the process will be woken up the moment
that time is over.
</OT>
So your only option is to ask the question in a newsgroup that is
dedicated to the operating system you are using. Perhaps it's
possible to achieve the time resolution you need, but you better
don't hold your breath. But perhaps there are also other approaches
to a solution of your problem which don't require such an exact
timing...
Regards, Jens
--
\ Jens Thoms Toerring ___
Je***********@physik.fu-berlin.de
\__________________________
http://www.toerring.de