What are trade offs for “busy wait” vs “sleep”?

前端 未结 6 1602
轻奢々
轻奢々 2020-12-02 10:15

This is an extension to my previous question

How does blocking mode in unix/linux sockets works?

What I gather from Internet now, all the process invoking bl

6条回答
  •  佛祖请我去吃肉
    2020-12-02 10:51

    First of all, you have a misconception:

    Blocking calls are not "busy waiting" or "spin locks". Blocking calls are sleepable -- that means the CPU would work on other task, no cpu are wasted.

    On your question on blocking calls

    Blocking calls are easier -- they are easy to understand, easier to develop, easier to debug.

    But they are resource hog. If you don't use thread, it would block other clients; If you use thread, each thread would take up memory and other system resource. Even if you have plenty of memory, switching thread would make the cache cold and reduce the performance.

    This is a trade off -- faster development and maintainability? or scalability.

提交回复
热议问题