Definition:

  • Thread is an execution unit that is part of a Process
  • A process can have multiple threads executing at the same time
  • Multi-threading

User and Kernel threads:

  • User threads - management done by user-level threads library, e.g., Pthreads (Linux), Java threads
  • Kernel threads - supported by the Kernel, e.g., Linux, MacOS

Multithreading models:

  • Many-to-One
    • Many user-level threads mapped to single kernel thread
    • One thread blocking causes all to block
  • One-to-one
    • Each user-level thread maps to kernel thread
      • Creating a user-level thread creates a kernel thread
      • Number of threads per process sometimes restricted due to overhead
  • Many-to-Many:
    • Allows many user level threads to be mapped to many kernel threads
    • Allows OSs to create a sufficient number of kernel threads
    • Not very common
  • Hybrid (2-level)

Threading issue:

  • Semantics of fork() and exec() system calls
    • fork(): duplicate only the calling thread or all threads
  • exec(): replace the running process including all threads
  • Signal handling: Synchronous and asynchronous
  • Thread cancellation of target thread
    • Asynchronous (immediately) or deferred (periodically)
  • Thread-local storage: own copy of data
  • Scheduler activations: Lightweight process (LWP)