Threads vs. Async

后端 未结 6 1523
盖世英雄少女心
盖世英雄少女心 2020-12-02 05:39

I have been reading up on the threaded model of programming versus the asynchronous model from this really good article. http://krondo.com/blog/?p=1209

However, the

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 05:56

    see http://en.wikipedia.org/wiki/Thread_(computing)#I.2FO_and_scheduling

    However, the use of blocking system calls in user threads (as opposed to kernel threads) or fibers can be problematic. If a user thread or a fiber performs a system call that blocks, the other user threads and fibers in the process are unable to run until the system call returns. A typical example of this problem is when performing I/O: most programs are written to perform I/O synchronously. When an I/O operation is initiated, a system call is made, and does not return until the I/O operation has been completed. In the intervening period, the entire process is "blocked" by the kernel and cannot run, which starves other user threads and fibers in the same process from executing.

    According to this, your whole process might be blocked, and no thread will be scheduled when one thread is blocked in IO. I think this is os-specific, and will not always be hold.

提交回复
热议问题