usleep in windows ?


Hi all

i have one program in linux , in which i use usleep function which
takes microsecond value . however in windows there is sleep taking
milisecond . is there any way or function to sleep for microseconds
in windows ?

thanks in advance .

sorry for bad english.
closed account (S6k9GNh0)
What would you honestly need microseconds for?
With bus clock ticks measured in nanoseconds and CPU ticks measured in picoseconds, even a microsecond can be a substantial amount of time. Unfortunately, though the sleep function in windows takes a milliseconds parameter, the smallest delay it can provide is typically around 10ms, and even that is not guaranteed or consistent.

There is no microsecond sleep in windows. It might be possible in assembly to create your own delay by knowing the CPU frequency and calculating the number of CPU cycles it takes to perform a push/pop. However, you might run into trouble with this method, especially if your CPU can clock down for power saving or because of overheating. If you are determined to get an accurate microsecond delay, I think what you really need is an RTOS.
there is nanosleep in windows i think..plzzz google.
I think there's a nanosleep function in linux, but I didn't think there was one in windows. I could easily be wrong, though. I suspect that there will still be problems with any function such as nanosleep. The OS can decide to run some other task during that time, and the delay could easily be several milliseconds before your program can resume. If you need to accurately delay for such a short time, I think your solution needs to be an RTOS or something much closer to hardware-level.
Yes -- jdd hit it right on the head. If your user application code needs to measure time accurate to microseconds, then the code cannot be expected to work under any kind of load at all due to CPU scheduling. Said code can only execute inside the kernel with that kind of timing accuracy.

(nanosleep in linux amounts to a busy loop, btw, consuming 100% cpu, since the finest grained timing mechanism available to Linux is one millisecond)
hmmm..i was not sure..thats why wrote google.. :P
Topic archived. No new replies allowed.