现在的位置: 首页 > 综合 > 正文

“用户级线程”和“内核级线程”概念上的迷糊

2013年09月15日 ⁄ 综合 ⁄ 共 972字 ⁄ 字号 评论关闭

线程的实现可以分为两类:用户级线程(User-Level Thread)和内核线线程(Kernel-Level Thread).后者又称为内核支持的线程或轻量级进程.

用户线程指不需要内核支持而在用户程序中实现的线程,其不依赖于操作系统核心,应用进程利用线程库提供创建、同步、调度和管理线程的函数来控制用户线程。

 

内核线程: 由操作系统内核创建和撤销。内核维护进程及线程的上下文信息以及线程切换。一个内核线程由于I/O操作而阻塞,不会影响其它线程的运行。Windows   NT和2000/XP支持内核线程  

 

用户线程:由应用进程利用线程库创建和管理,不以来于操作系统核心。不需要用户态/核心态切换,速度快。操作系统内核不知道多线程的存在,因此一个线程阻塞将使得整个进程(包括它的所有线程)阻塞。由于这里的处理器时间片分配是以进程为基本单位,所以每个线程执行的时间相对减少。

 

其实这个问题更应该这样问:线程管理机制在内核级实现和用户级实现的区别是什么。 

操作系统:设计与实现中,对于这个问题是这样解释的: 

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. 

 

参考资料:

http://book.51cto.com/art/201006/206946.htm

http://topic.csdn.net/t/20031007/11/2329743.html

 

 

抱歉!评论已关闭.