Is there an alternative for sleep() in C?

后端 未结 16 1930
无人及你
无人及你 2020-12-02 14:55

In traditional embedded programming, we will give a delay function like so:

for(i=0;i<255;i++)
   for(j=0;j<255;j++);

In the micropro

16条回答
  •  無奈伤痛
    2020-12-02 15:37

    sleep actually interfaces with operating system, where sleeping processes are placed outside of scheduling queue. I usually use:

    poll(0, 0, milliseconds);
    

    for POSIX compliant systems. select also works for windows (they must have a native API (probably called Sleep) for that.)

提交回复
热议问题