1、linux 系统环境下 有库函数 usleep
    2、windows 系统环境下 没有usleep
    3、windows 系统环境下模拟 linux 实现 usleep

    1. #ifdef _WIN32
    2. #include <windows.h>
    3. #define sleep(sec) Sleep(sec * 1000)
    4. #define msleep(msec) Sleep(msec)
    5. static void usleep(unsigned long usec)
    6. {
    7. HANDLE timer;
    8. LARGE_INTEGER interval;
    9. interval.QuadPart = -(10 * usec);
    10. timer = CreateWaitableTimer(NULL, TRUE, NULL);
    11. SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0);
    12. WaitForSingleObject(timer, INFINITE);
    13. CloseHandle(timer);
    14. }
    15. #else
    16. #include <unistd.h>
    17. #define msleep(msec) usleep(msec * 1000)
    18. #endif
    19. int main(int argc, char *argv[])
    20. {
    21. sleep(1);
    22. msleep(100);
    23. usleep(1000);
    24. }