User-Level Thread

Introduction

完全在 user space 中實作的 thread, kernel 把這個 process 是為 single thread 而不知其中有多個 thread

Run-time System

run-time system 是為了管理 user-level threads 的程式碼,他負責

  • 建立和銷毀 thread
  • thread context switch
  • scheduling
  • 處理 mutex、condition variable 同步問題

Thread Table

run-time system 維護了一個 thread table,他紀錄了每個 thread 的

  • program counter
  • stack pointer
  • register
  • state

Problem with Implementation

Blocking System Call

如果一個 thread 呼叫了 blocking system call,因為 kernel 不知道我們是 multithread,結果就 blocking 了

解決方法是 run-time system 會截取這些 system call,然後用 non-blocking 或 I/O multiplexing 的 system call 代替

Scheduling

kernel 會幫 process context switch,但沒有人會幫 multithread process 在 running state 做 context switch 除非這個 thread 主動讓出 CPU

解決方法是 run-time system 可能會向 kernel 求取 alarm,然後用 system handler 來進行 user-level thread 的 context switch