I was talking with someone in my CSE class and they said:
They wrote:
I once read that sleep and usleep should never be used simply because the parameter given is the minimum time to sleep, but the system is free to take longer for any reason.
Thoughts? I personally think this is stupid:
I wrote:
Well, that reason is incredibly stupid IMHO. The OS could theoretically take however long it wants to do anything that you tell it to do...
I saw usleep(1) takes more than 50 microseconds in some embedded system. A faster CPU can give you a more accurate result. But if you want really accurate function, you may need to use a loop that keeps checking the time stamp using assembly commands.
The granularity of usleep cannot be any finer than that of the hardware clock. As long as the kernel can execute code
when a clock interrupt occurs, the kernel *could* context switch at that point.
You should be aware that some (perhaps older) platforms would busy-loop in the kernel to emulate sleeps of
less than some threshold (like 1 or 2 msecs).