How is sleep implemented at the OS level?

前端 未结 6 1247
我在风中等你
我在风中等你 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:38

    Sleep blocks your task/thread for the time value passed. Your task becomes un-runnable for that period or until something else interesting happens (like a signal), whichever is sooner.

    It is not uncommon for sleep to call select() and pass no descriptors to wait on and a timeout value equal to your sleep period.

    The system may implement this by setting a timer to expire after the time passed and then waiting on a semaphore that will be signalled when that timer expires. Thus it is blocked on that semaphore.

提交回复
热议问题