【正文】
obtain the correct result for C = A + B ?三種線程狀態(tài) : running, ready, blocked ?線程無掛起狀態(tài) ?Termination of a process, will terminates all threads within the process Threads States(線程狀態(tài) ) User Level Threads(ULT) ? 內(nèi)核不關(guān)注線程的存在 ? 所有的線程管理由應(yīng)用程序通過調(diào)用 ULT庫實(shí)現(xiàn) ? 線程間的切換無需內(nèi)核模式下的特權(quán)指令(無模式轉(zhuǎn)換) ? 線程調(diào)度由特定的應(yīng)用 程序完成 ? 例子 POSIX Pthreads Mach Cthreads 一種 UNIX的操作系統(tǒng) ,采用微內(nèi)核 Solaris threads User Level Threads library 用戶級線程庫 ? Contains codes for: (包含以下代碼 ) – creating and destroying threads(線程的創(chuàng)建和撤消 ) – passing messages and data between threads 線程間數(shù)據(jù)和消息的傳遞 – scheduling thread execution 對線程的調(diào)度 – saving and restoring thread contexts 對線程上下文的保存和恢復(fù) ? Advantages ? Thread switching does not involve the kernel: no mode switching 無模式 (管態(tài) /目態(tài) )轉(zhuǎn)換 ? Scheduling can be application specific: choose the best algorithm. 可選擇最好的調(diào)度算法 ? ULTs can run on any OS. Only needs a thread library 只要有庫 ,就可在任何操作系統(tǒng)運(yùn)行 ? Inconveniences ? Most system calls are blocking and the kernel blocks processes. So all threads within the process will be blocked 多數(shù)的系統(tǒng)調(diào)用將阻塞該進(jìn)程的所有線程 ? The kernel can only assign processes to processors. Two threads within the same process cannot run simultaneously on two processors 一個(gè)進(jìn)程的兩個(gè)線程不能同在兩個(gè)處理器上同時(shí)運(yùn)行 用戶級線程的優(yōu)缺點(diǎn) Kernel Level Threads(KLT) 內(nèi)核級的線程 ? 內(nèi)核完成對所有線程的管理 ? 無線程庫,但內(nèi)核供內(nèi)核線程的編程接口( API) ? 內(nèi)核需要維護(hù)進(jìn)程和線程的上下文信息 ? 線程間的調(diào)度由內(nèi)核完成 ? 調(diào)度的基本單位是線程 ? 例子 Windows 95/98/NT/2020