Sleep function in Windows, using C

前端 未结 4 1009
一生所求
一生所求 2020-11-28 11:42

I need to sleep my program in Windows. What header file has the sleep function?

4条回答
  •  没有蜡笔的小新
    2020-11-28 12:15

    Include the following function at the start of your code, whenever you want to busy wait. This is distinct from sleep, because the process will be utilizing 100% cpu while this function is running.

    void sleep(unsigned int mseconds)
    {
        clock_t goal = mseconds + clock();
        while (goal > clock())
            ;
    }
    

    Note that the name sleep for this function is misleading, since the CPU will not be sleeping at all.

提交回复
热议问题