其实楼主应该这么问,线程管理机制在内核级实现和用户级实现的区别是什么。
Although these two alternatives may seem equivalent, they differ considerably in performance. Switching threads is much faster when thread management is done in user space than when a kernel call is needed. This fact argues strongly for doing thread management in user space. On the other hand, when threads are managed entirely in user space and one thread blocks(e.g., waiting for I/O or a page fault to be handled), the kernel blocks the entire process, since it is not even aware that other threads exist.
以上引自Operating Systems: Design and Implementation, 2 Editon
内核级支持线程(以下简称内线)和用户级支持现成(用线)的区别在于:
1.内线的switch比用线的效率低,因为用线在switch的时候要从用户态转为内核态,再从内核态转为用户态,牵涉的系统工作较多,所以效率低。
2.但是当一个用线的线程block后,比如进行i/o操作,那么i/o操作就是内核态的执行,大家都知道内核态的优先级高于用户态的,那么事实上这个i/o操作就占据了cpu(当然其他进程的线程有可能跟他争夺的,因为系统毕竟在内核级支持多进程的),根本不管用线的其他线程的,因为用线的多线程管理程序本身也是用户态的,不可能中止在内核态运行的这个i/o操作而调度其他的线程。线程本来就是进程的细分,但是用线的这种情况,就跟只是支持多进程没什么多大的区别了,there are still some differences, if not none.