Welcome 歡迎光臨! 愛上網路 - 原本退步是向前

Multi-threading 介紹

user threads and kernel threads
a. User threads
在 user mode 下進行,OS 不知道有這些 thread 存在不需要 OS 介入管理。
 
優點:產生、管理成本較低
缺點:若 process 的 user thread 發出鎖定的 system call 且 kernel 是 single thread 則整個 process 被鎖住。
 
常見的 user thread

Pthreads (POSIX threads)

Win32 threads

Java threads 

 
 
b. Kernel thread
在 kernel mode 下進行,OS 知道有這些 thread 存在,由 OS 介入管理。
常見的 kernel threads

Windows XP/2000

Solaris

Linux

Tru64 UNIX

[Multi-threads 例題](112年全國教師甄試)
有兩個 Process P_A 與 P_B,P_A 三 條thread、P_B 兩條thread,若 OS 採平均分配原則來分配 CPU Time,則 P_A 與 P_B 各分多少 % 之 CPU Time?
User thread   
Kernel thread
 
Ans :
Kernel 不知道有 user thread,只知道有 P_A 與 P_B 兩個 process。P_A 與 P_B 各分到 50% 的 CPU Time。
有 5 條 thread 欲分配,每條可分到 20% 的 CPU time。
P_A 分到 3×20% = 60% 的 CPU time。
P_B 分到 2×20% = 40% 的 CPU time 。
 

[ 資訊科技 ] 瀏覽次數 : 141 更新日期 : 2023/09/19