How is sleep implemented at the OS level?

前端 未结 6 1250
我在风中等你
我在风中等你 2020-12-01 11:51

I am just interested how sleep(time in ms) is implemented in a C library or basically at the OS level...

I am guessing...

  1. May be the based
6条回答
  •  天涯浪人
    2020-12-01 12:44

    The answer to your question is completely operating-system and implementation-dependent.

    A simple way to think about it: When you call sleep(), the OS calculates the wakeup time, then sticks your process on a priority queue somewhere. It then just doesn't schedule your process to get any execution time until enough real time has passed for it to get popped off the queue.

提交回复
热议问题