1 Thread 2 Thread vs Process 3 Thread

  • Slides: 9
Download presentation

目錄 1 Thread 2 Thread vs. Process 3 Thread的種類 4 死結 5 參考資料 2

目錄 1 Thread 2 Thread vs. Process 3 Thread的種類 4 死結 5 參考資料 2

Thread v 何謂Thread? § Thread of execution is a fork of a computer program

Thread v 何謂Thread? § Thread of execution is a fork of a computer program into two or more concurrently running tasks. § Light Process § 執行緒之間的執行是無關的 § 在Java程式中,每個程式都包含一個以上的thread. § 多cpu能真正發揮其效能 v fork § 當process fork,會複製產生一個child process,原本的 process則稱為parent process. § Unix 底下使用wait(), waitpid()回收zombie 3

Fork示意圖 Parent process C D S child process fork D S child thread 註:C

Fork示意圖 Parent process C D S child process fork D S child thread 註:C for code segment S D for data segment S for stack

Thread vs. Process Thread Heavyweight process lightweight process 各process無法共享 可以共享 資源 (ex: Memory space)

Thread vs. Process Thread Heavyweight process lightweight process 各process無法共享 可以共享 資源 (ex: Memory space) Context Switching負 較輕 荷重 可發揮多cpu的功效 5

Thread的種類 v Kernel Thread § 由kernel直接生產 § 分為user與kernel用兩部份(user用叫Lightweight process) v User Thread § 由Library提供

Thread的種類 v Kernel Thread § 由kernel直接生產 § 分為user與kernel用兩部份(user用叫Lightweight process) v User Thread § 由Library提供 § 舉凡它的 Creating, Scheduling, Synchronization, Managing. . . 都由 Library 負責 § Kernel 完全不知道它的存在. 6

參考資料 v Java Threads(O’REILLY) v 維基百科 § http: //www. wikipedia. org/ v 梁明章教授上課投影片 §

參考資料 v Java Threads(O’REILLY) v 維基百科 § http: //www. wikipedia. org/ v 梁明章教授上課投影片 § http: //noc. twaren. net/~liangmc/nuk/nsm 971/Lesson 1 1. pdf 8