Application:
#include <syswait.h>
Usleep (n)//n μs
Sleep (n)//n ms
Sleep (N)//n sec
Drivers:
#include <linux/delay.h>
Mdelay (n)//milliseconds its 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
Calling Asm/delay.h's udelay,udelay should be nanosecond-delay.
Dos:
Sleep (1); Stay for 1 seconds
Delay (100); Stay 100 milliseconds
Windows:
Sleep (100); Stay 100 milliseconds
Linux:
Sleep (1); Stay for 1 seconds
Usleep (1000); Stay 1 milliseconds
Each platform is not the same, it is best to define a set of cross-platform macro control
Seconds or microseconds? About the delay function sleep () because the sleep () function is required to write a piece of code, in my Mind, sleep (10) seems to be dormant for 10 microseconds, and the result is 10 seconds of hibernation (under Linux). It's strange, because the chief remembers it as if it were microseconds. So I looked it up a bit. The original Sleep function prototype under Linux is: unsigned int sleep (unsigned int seconds), while the Sleep function prototype in MFC is: void Sleep (DWORD Dwmilliseco NDS); That is, the sleep () function is in seconds, sleep (1), or dormant for 1 seconds, under Linux (using the GCC library). While the sleep () function under MFC is in microseconds, sleep (1000) is dormant for 1 seconds. Oh, yes. If you sleep with a subtle unit under Linux, you can use the thread sleep function: void Usleep (unsigned long usec); Of course, don't forget the # include <system.h> oh when you use it. Also worth mentioning is that there is a delay () function under Linux, the prototype is extern void delay (unsigned int msec), it can delay msec*4 milliseconds, that is, if you want to delay a second, you can use delay (250);
Linux Sleep Usage