Why use select() instead of sleep()?

后端 未结 6 832
执笔经年
执笔经年 2020-12-31 04:28

I\'m working through a chapter about iPhone audio and have come across a section of code that I can\'t make sense of:

while (aqc.playPtr < aqc.sampleLen)          


        
6条回答
  •  无人及你
    2020-12-31 05:10

    Well, sleep(3) may be implemented by using signals. It depends on the platform.

    When you use select(2) and poll(2), you know that no signals will be involved, which is often very useful. For example, if you are using alarm(2), you should not use sleep(3) as well, because "mixing calls to alarm and sleep is a bad idea" (according to the man page.)

    Also, select and poll give you millisecond granularity when sleeping, but sleep only has a granularity in terms of seconds.

提交回复
热议问题