threads_concepts.excalidraw

⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’

Excalidraw Data

Text Elements

Threads

Kernel

Multi threading model

Signal handling

Resource Sharing

Link to original

Threads are fundamental units of CPU utilization

process-vs-threads.excalidraw

⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’

Excalidraw Data

Text Elements

Code

Data

Files

Registers

Stack

one thread

Code

Data

Files

Registers

Stack

Registers

Stack

Registers

Stack

Link to original

They consist of:

  • PC
  • Stack
  • Set of registers
  • Thread ID (TID)

Processes have a single thread Multithreaded processes have multiple threads

Why?

  • Responsive - threads are not blocked by other threads that take longer
  • Resource Sharing - creating and managing single address space threads is faster for processes
  • Scalability - utilization of multiproessor architecture

Challenges:

  • Dividing activity
  • Balance - not wasting threads on trivial tasks
  • Data Splitting - stop threads from interfering
  • Data Dependency - if one task depends on result of another task needs to be synchronized
  • Testing + Debugging - harder due to race conditions

Threads can either be:

  • User-level
  • Kernel-level

Multithreading Models

threading-models.excalidraw

⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’

Excalidraw Data

Text Elements

Multithreading

Many to One

One-to-one

Many-to-many

Two-level

Link to original

Multithreading Models:

Many-to-one

many user-level threads mapped to one kernel thread:

  • efficient
  • entire process blocks if blocking system call occurs
  • does not allow process to be split across CPUs

many-to-one.excalidraw

⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’

Excalidraw Data

Text Elements

thread

thread

thread

thread

K

Link to original

One-to-one

  • Each user thread maps to kernel thread
  • Not blocked by system call
  • More overhead, slow system

one-to-one.excalidraw

⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’

Excalidraw Data

Text Elements

K

thread

thread

thread

K

K

Link to original

Many-to-many

many user-level threads mapped to many kernel threads

  • no limit to number of threads

many-to-many-model.excalidraw

⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’

Excalidraw Data

Text Elements

K

thread

thread

thread

thread

K

K

Link to original

Two-level

Many-to-one + Kernel threads

two-level.excalidraw

⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’

Excalidraw Data

Text Elements

K

thread

thread

thread

thread

K

K

K

thread

Link to original

Thread Cancellation

Asynchronous

  • Immediate Deferred
  • Peridically checks if should be cancelled according to flag

Signal Handling

Deliver signal to thread which it applies Delivers to every thread ceertain threads in process specific thread receiving all signals of process

Thread pools:

  • pool of threads where they await
  • number of threads bound to size of pool
  • slightly faster