User/Kerval level thread
User-level threads have no kernel support, so they are very inexpensive to ceate, destroy, and switch among.
However, if one blocks, the whole process blocks.
Kerval-supported threads are more expensive because system calls are needed to create and destroy them and the kernel must schedule them.
They are more powerful because they are independently scheduled and block individually.
User Thread
Def
Thread management是由在user site端之thread library負責(i.e., 提供API供user process使用),完全不須kernel介入,kernel不知道有user thread存在。
Thread發出Blocking system call
會導致整個process一同blocked,even if there is available user thread in a process。
Multiprocessor架構之效益發揮
差
Thread management cost
低, context switching負擔較低
Kernel Thread
Def
Thread management完全由kernel負責
Thread發出Blocking system call
不會導致整個process blocked, kernel可切給另一個thread執行。
Multiprocessor架構之效益發揮
佳, (同一個process之不同thread可在不同的processor上平行執行。)
Thread management cost
高, slower context switching.
Thread的特性
- User threads run faster than kernel threads
- If the kernel is single-threaded, any user-level thread performing a blocking system call will cause the entire process to block, even if other threads are available to run within the application.
- Using threads can increase the utilization of a multi-processor system.
- Each user thread must have its own stack in the application.
- Pthreads defines the specification.