Threads

    Cards (13)

    • Thread
      A lightweight process created within a normal (heavyweight) process
    • Multithreading
      The ability of an operating system to support multiple threads of execution within a single process
    • Threads
      • Processes have at least one thread of control
      • Multiple threads run in the same address space, share the same memory areas
      • The creation of a thread only creates a new thread control structure, not a separate process image
    • It depends on the actual kernel implementation how threads are managed
    • Thread Control Block
      A saved thread context when not running, containing: thread identifier, stack pointer, program counter, state, register values, pointer to process control block
    • Thread states

      Running, Ready, Blocked
    • There are four basic operations for managing threads: Spawn/create, Block, Unblock, Finish
    • User-level threads
      Operating system unaware of threads, completely controlled by user program
    • User-level threads

      • Thread library functions manage threads
      • Light thread switching in user mode
      • No mode switch necessary
      • Can implement own thread scheduling
    • Kernel-level threads

      Operating system manages threads, better mapping to multiple CPU cores
    • Kernel-level threads
      • Kernel manages each thread separately
      • Fine-grained scheduling by kernel
      • If one thread blocks, another can be scheduled without blocking the whole process
      • Threads can be distributed to multiple processors and run in parallel
    • Kernel-level threads have significant overhead and increase in kernel complexity
    • A mode switch to kernel mode is required to transfer control from one kernel-level thread to another in a process
    See similar decks