Docsity

Processes & Threads: Multiprogramming & Thread Implementation, Slides of Operating Systems

Partial preview of the text

Download Processes & Threads: Multiprogramming & Thread Implementation and more Slides Operating Systems in PDF only on Docsity!

Processes

Part I Processes & Threads

Process

  • A program in execution
  • An instance of a program running on a computer
  • The entity that can be assigned to and executed on a processor
  • A unit of activity characterized by
    • the execution of a sequence of instructions
    • a current state
    • an associated set of system resources

Multiprogramming

  • The interleaved execution of two or more computer programs by a single processor
  • An important technique that
    • enables a time-sharing system
    • allows the OS to overlap I/O and computation, creating an efficient system

Processes

The Process Model

  • Multiprogramming of four programs
  • Conceptual model of 4 independent, sequential processes
  • Only one program active at any instant

Cooperating Processes (I)

  • Sequential programs consist of a single process
  • Concurrent applications consist of multiple cooperating processes that execute concurrently
  • Advantages
    • Can exploit multiple CPUs (hardware concurrency) for speeding up application
    • Application can benefit from software concurrency, e.g., web servers, window systems

Cooperating Processes (II)

  • Cooperating processes need to share information
  • Since each process has its own address space, OS mechanisms are needed to let process exchange information
  • Two paradigms for cooperating processes
    • Shared Memory
      • OS enables two independent processes to have a shared memory segment in their address spaces
    • Message-passing
      • OS provides mechanisms for processes to send and receive messages

10

Threads

The Thread Model (1) (a) Three processes each with one thread (b) One process with three threads

11

The Thread Model (2)

  • Items shared by all threads in a process
  • Items private to each thread

13

Thread Usage (1)

A word processor with three threads

14

Thread Usage (2)

A multithreaded Web server

Thread Implementation - Packages

  • Threads are provided as a package, including operations to create, destroy, and synchronize them
  • A package can be implemented as:
    • User-level threads
    • Kernel threads

17

Implementing Threads in User Space

A user-level threads package

User-Level Threads

  • Thread library entirely executed in user mode
  • Cheap to manage threads
    • Create: setup a stack
    • Destroy: free up memory
  • Context switch requires few instructions
    • Just save CPU registers
    • Done based on program logic
  • A blocking system call blocks all peer threads

Kernel-Level Threads

  • Kernel is aware of and schedules threads
  • A blocking system call, will not block all peer threads
  • Expensive to manage threads
  • Expensive context switch
  • Kernel Intervention