Try   HackMD

Operating System #4

Process VS Thread

  • 一個Process一定至少有一個Thread,也有可能有很多個。
  • Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 多Threads的好處:
    • 部分Thread當機,對於該Process來說可能還是可以基本運作
    • 資源的共享更容易(如上圖架構,可以直接共享程式碼和全域變數等)
    • 不必使用fork的方式,降低成本
    • 簡單迎合多核架構
  • 相對於single-core system,多核架構可以同時間執行多個Process/Thread

Multicore Programming

  • 在平行化的架構中,可以分為兩類:
    • Data parallelism:根據資料分割,避免需要同步資料的情形
    • Task parallelism:根據任務去分類,可能會遇到資料同步的問題,但分割得更佳漂亮
  • Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

User Threads and Kernel Threads

  • User threads:在User層提供多Thread的library,但可能在系統還是連結到同一個core。
  • Kernel threads:系統層提供的Thread。
  • 在User threads 對 Kernel threads的架構中,有many-to-one、one-to-one和many-to-many。
    • 多對少的情況代表了什麼?代表雖然user層的lib提供給你多個Thread的架構,然而到系統層還是得排隊,等候OS選擇thread才能執行。
    • 舉例:老師將獎學金申請書分成個人資料、學業資料兩個部分,讓同學可以分開繳交;然而將資料交至學務處後卻是同一個職員處理,實際上並沒有達到加速的功能。
  • 而Kernel threads是OS開放出來的接口,後面一樣要對應到硬體方面支不支援多核架構。即便作業系統有多個Thread的處理,若CPU沒有能力處理也沒有用。
tags: note