Application:
# Include <syswait. h>
Usleep (n) // n microseconds
Sleep (n) // n Ms
Sleep (n) // n seconds
Driver:
# Include <Linux/delay. h>
Mdelay (n) // milliseconds implementation
# Ifdef notdef
# Define mdelay (N )(\
{Unsigned long MSEC = (n); While (MSEC --) udelay (1000 );})
# Else
# Define mdelay (N )(\
(_ Builtin_constant_p (n) & (n) <= max_udelay_ms )? Udelay (n) * 1000 ):\
({Unsigned long MSEC = (n); While (MSEC --) udelay (1000 );}))
# Endif
Call the udelay of ASM/delay. h. The udelay should be a latency of nanoseconds.
DoS:
Sleep (1); // stay for 1 second
Delay (100); // stay at 100 ms
Windows:
Sleep (100); // stay for 100 milliseconds
Linux:
Sleep (1); // stay for 1 second
Usleep (1000); // stay for 1 ms
Every platform is not the same. It is best to define a set of cross-platform macro control.
Second or microsecond? The sleep () function is required to write a piece of code about the latency function sleep (). In my impression, sleep (10) seems to be sleeping for 10 microseconds, the result is sleep for 10 seconds (in Linux ). I think it's strange, because I remember it was measured in microseconds. So I checked it. The original sleep function in Linux is prototype: Unsigned int sleep (unsigned int seconds); the sleep function in MFC is prototype: void sleep (DWORD dwmilliseconds); that is, in Linux (the GCC library used), the sleep () function is in seconds, sleep (1); that is, sleep for 1 second. The sleep () function in MFC is measured in microseconds, and sleep (1000) is 1 second of sleep. So it turns out. In Linux, if you also use the subtle sleep unit, you can use the thread sleep function: void usleep (unsigned long USEC). Of course, do not forget # include <system. h> oh. It is also worth mentioning that there is a delay () function in Linux, prototype: extern void delay (unsigned int msec); it can delay msec * 4 ms, that is, if you want to delay one second, you can use delay (250 );