1753474 Members
4814 Online
108794 Solutions
New Discussion юеВ

USLEEP -vs- NANOSLEEP

 
SOLVED
Go to solution
tony j. podrasky
Valued Contributor

USLEEP -vs- NANOSLEEP

Hello group;

I have an old laptop that wasn't doing anything, so I loaded Linux on it and wrote a program to send my e-mail in morse code (so I can "listen" to my e-mail while I do other things).

I'm using "usleep" to time the length of the morse code bits.

The problem is that usleep does not appear to work uniformly i.e. I have a formula to change the speed of the morse code - but although the speed should change progressively, it does not.

After reading the manpage I'm guessing that the system is truncating or rounding-off the time (note that the CPU/IO/memory usage is close to nil).

Do [you] think if I rewrite the program to use "nanosleep" that I will see better performance?

regards,
tonyp

(as usual, any reply I get that at least gives me something worth investigating will get 5 points. Replies that lead to the solution will get 10)
REMEMBER: Once you eliminate your #1 problem, #2 gets a promotion.
2 REPLIES 2
Matt Palmer_2
Respected Contributor
Solution

Re: USLEEP -vs- NANOSLEEP

Hi,

this person seems to think that nanosleep gave him more accurate results.

http://cc.byexamples.com/2007/05/25/nanosleep-is-better-than-sleep-and-usleep/

regards

Matt
tony j. podrasky
Valued Contributor

Re: USLEEP -vs- NANOSLEEP

Matt: thanx for the URL.

They have the answer there. Now all I need to do is figure out how to use their function in my program. :-)

regards,
tonyp
REMEMBER: Once you eliminate your #1 problem, #2 gets a promotion.