-
Comparison of use level and kernel level thread - [康朴塔散思]
2009-06-25
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://damocles.blogbus.com/logs/41488892.html
http://www.northco.net/chenke/project/linux.html
User-Level Threads
User-level threads avoid the kernel entirely and manages the tables itself. User-level threads employ what is oftentimes called "cooperative multitasking" where the task defines a set of routines that get "switched to" by manipulating the stack pointer. The big advantage of user-level threads is they can switch faster than kernel level threads.One of the main disadvantages is that user-level threads have a problem that a single thread can monopolize the time slice, creating starvation among other threads within the tast. Also, user-level threads have no way of taking advantage of Symmetric MultiProcessor systems like a dual-pentium. Last, when a thread becomes I/O blocked, all other threads within the tast lose the timeslice as well.
Some user-thread libraries have provided solutions to these problems with work-arounds. Timeslice monopolization was addressed by controlling it with an external monitor that uses its own clock tick. I/O blocking can be solved by creating special wrappers over system calls or the task can be written for nonblocking I/O.
Kernel-Level Threads
Kernel-level threads are implemented in the kernel using several tables (each task getting a table of threads). The kernel schedules each thread within the timeslice of each process. There is more overhead with switching in kernel-level threads but Linux's kernel-level threads perform nearly as well as user-level.Linux can operate by using either entirely user-level or entierly kernel-level threads or a combination of both. Advantages for using kernel-level threads is that it's less likely for a thread to monopolize a timeslice. Also, I/O blocking is not a problem. If properly coded, the process can automatically take advantage of SMPs as well and will runn incremently faster with each CPU added.
随机文章:
Thread Clustering 2009-06-25What are threads (user/kernel)? 2008-09-13How to detect VMWare 2009-07-07图片文件大写后缀名无法打开问题解决方法 2008-09-27
收藏到:Del.icio.us







