Sleeping for milliseconds on Windows, Linux, Solaris, HP-UX, IBM AIX, Vxworks, Wind River Linux?

后端 未结 3 997
深忆病人
深忆病人 2020-12-10 13:02

I have to write a C program which has to sleep for milliseconds, which has to run on various platforms like Windows, Linux, Solaris, HP-UX, IBM AIX, Vxworks, and Windriver L

3条回答
  •  佛祖请我去吃肉
    2020-12-10 13:52

    Consider select with empty FD sets and the timeout you want. From man select:

    Some code calls select() with all three sets empty, nfds zero, and a non-NULL timeout as a fairly portable way to sleep with subsecond precision.

    Actually it might be the best solution for any non-Windows system.

提交回复
热议问题