Docsity

Threads Two - Operating Systems - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Threads Two - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Operating Systems

Lecture 08:

Threads

Processes vs. Threads

  • A process viewed so far as units of:
    • Resource ownership
    • Scheduling/execution
  • In multithreading OS:
    • Process stays the unit of resource ownership
    • Thread (or lightweight process ) is the unit of scheduling
  • Multithreading: the ability of an OS to

support multiple, concurrent paths of

execution within a single process Docsity.com^2

One or More Threads

in a Process

Each thread in a process has:

  • A thread execution state (Running, Ready, etc.)
  • A saved thread context when not running; one way to view a thread is as an independent program counter operating within a process
  • An execution stack
  • Some per-thread static storage for local variables
  • Access to the memory and resources of its process, shared with all other threads in that process

Threads vs. Processes

Thread Use in a

Single-User System

• Foreground and background work

• Asynchronous processing

• Speed of execution

• Modular program structure

Threads

  • In an OS that supports threads, scheduling

and dispatching is done on a thread basis

  • Most of the state information dealing with

execution is maintained in thread-level data

structures

  • suspending a process involves suspending all threads of the process
  • termination of a process terminates all threads within the process

2 RPCs with

single thread

and multi- threading

Multithreading on a Uniprocessor

User-Level Threads (ULTs)

  • All thread management is done by the application
  • The kernel is not aware of the existence of threads

Relationships Between ULT

States and Process States

Figure 4.6 Examples of the Relationships between User-Level Thread States and Process States

Disadvantages of ULTs

  • In a typical OS many system calls are blocking

 as a result, when a ULT executes a system call, not only is that thread blocked, but all of the threads within the process are blocked

  • In a pure ULT strategy, a multithreaded

application cannot take advantage of multiprocessing

Kernel-Level Threads (KLTs)

  • Thread management is done by the kernel - no thread management is done by the application - Windows is an example of this approach

Disadvantage of KLTs

The transfer of control from one thread to

another within the same process

requires a mode switch to the kernel

This image cannot currently be displayed.

Combined Approaches

  • Thread creation is done in the user space
  • Bulk of scheduling and synchronization of threads is by the application
  • Solaris is an example