How do you add a timed delay to a C++ program?

后端 未结 14 2159
情话喂你
情话喂你 2020-11-28 02:11

I am trying to add a timed delay in a C++ program, and was wondering if anyone has any suggestions on what I can try or information I can look at?

I wish I had more

14条回答
  •  佛祖请我去吃肉
    2020-11-28 02:35

    Yes, sleep is probably the function of choice here. Note that the time passed into the function is the smallest amount of time the calling thread will be inactive. So for example if you call sleep with 5 seconds, you're guaranteed your thread will be sleeping for at least 5 seconds. Could be 6, or 8 or 50, depending on what the OS is doing. (During optimal OS execution, this will be very close to 5.)
    Another useful feature of the sleep function is to pass in 0. This will force a context switch from your thread.

    Some additional information:
    http://www.opengroup.org/onlinepubs/000095399/functions/sleep.html

提交回复
热议问题