Threads

Thread Concept

Concurrent Programming

  • Single Process on Single Processor
  • Multiple Processes on Single Processor
  • Single Instruction Single Data
  • Multiple Instruction Multiple Data
  • Single Instruction Multiple Data (SIMD)
  • Zero Instruction Multiple Data (MIMD)

Speedup

Amdahl’s Law

  • where is serial portion, is number of cores

Gustafson’s law


Threading Model

User Level Thread (ULT)

user-level thread

Kernel Level Thread (KLT)

kernel-level thread

Multithreading Model

  • many-to-one: ULT
  • one-to-one: KLT
  • many-to-many (N:M): Hybrid
  • two level: similar to N:M, but allow user to bound user thread to kernel thread (for latency sensitive thread)

Synchronous vs. Asynchronous Threading

Asynchronous Threading

D-OS-Ch03e-Asynchronous_Threading

Synchronous Threading

D-OS-Ch03f-Synchronous_Threading

Implicit Threading

Implicit Threading vs. Explicit Threading

  • Implicit Threading: 將 thread 的建立、管理、銷毀都交給 compiler 決定,程式設計者只需要指出哪裡可以平行便可以 (e.g., OpenMP)
  • Explicit Threading: 由程式設計師自己管理 thread 週期 (e.g., pthread)

Thread Pool

D-OS-Ch03a-Thread_Pool

Worker Thread

D-OS-Ch03b-Worker_Thread

Thread Issues

fork() and exec() in Threads

threads vs. fork()

Signal Handling, Thread Cancellation

Thread-Local Storage (TLS)

D-OS-Ch03c-TLS

Scheduler Activation

D-OS-Ch03d-Scheduler_Activation