0% found this document useful (0 votes)
15 views35 pages

Understanding Processes and Threads in OS

Chapter 4 of 'Operating Systems: Internals and Design Principles' discusses the concepts of processes and threads, highlighting their characteristics, differences, and the benefits of multithreading. It explains user-level threads (ULTs) and kernel-level threads (KLTs), detailing their management, advantages, and disadvantages. The chapter also covers thread synchronization, applications that benefit from multithreading, and the relationship between processes and threads in operating systems.

Uploaded by

jshehayeb254
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views35 pages

Understanding Processes and Threads in OS

Chapter 4 of 'Operating Systems: Internals and Design Principles' discusses the concepts of processes and threads, highlighting their characteristics, differences, and the benefits of multithreading. It explains user-level threads (ULTs) and kernel-level threads (KLTs), detailing their management, advantages, and disadvantages. The chapter also covers thread synchronization, applications that benefit from multithreading, and the relationship between processes and threads in operating systems.

Uploaded by

jshehayeb254
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Operating

Systems:
Internals
and Design
Principles Chapter 4
Threads
Seventh Edition
By William Stallings
Processes and Threads
∗Processes have two characteristics:
Resource Ownership Scheduling/Execution
Process includes a virtual Follows an execution path
address space to hold the that may be interleaved
process image with other processes
◼ the OS performs a protection ◼ a process has an execution state
function to prevent unwanted (Running, Ready, etc.) and a
interference between processes dispatching priority and is
with respect to resources scheduled and dispatched by the
OS
Processes and Threads
◼ The unit of dispatching is referred to as a
thread or lightweight process
◼ The unit of resource ownership is referred
to as a process or task
◼ Multithreading
- The ability of an OS to
support multiple, concurrent paths of
execution within a single process
Single Threaded Approaches
◼ A single thread of
execution per process, in
which the concept of a
thread is not recognized,
is referred to as a single-
threaded approach
◼ MS-DOS is an example
Multithreaded Approaches
◼ The right half of Figure
4.1 shows multithreaded
approaches
◼ A Java run-time
environment is an
example of a system of
one process with
multiple threads
Processes
▪ The unit or resource allocation and a unit of
protection
▪ A virtual address space that holds the process image
▪ Protected access to:
➢ processors
➢ other processes
➢ files
➢ I/O resources
One or More Threads
in a Process

Each thread has:

• an execution state (Running, Ready, etc.)


• saved thread context when not running
• an execution stack
• some per-thread static storage for local
variables
• access to the memory and resources of its
process (all threads of a process share this)
Threads vs. Processes
Benefits of Threads

Less time to Threads enhance


terminate a efficiency in
thread than a communication
Takes less Switching between
process between programs
time to create two threads takes
a new thread less time than
than a switching between
process processes
Thread Use in a
Single-User System
◼ Foreground and background work
◼ Asynchronous processing
◼ Speed of execution
◼ Modular program structure
◼ 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
The key states for Thread operations
associated with a
a thread are: change in thread
state are:
◼ Running
◼ Ready ◼ Spawn
◼ Blocked ◼ Block
◼ Unblock
◼ Finish
RPC Using Single Thread
(Remote Procedure Call)
RPC Using One
Thread per Server
Multithreading
on a
Uniprocessor
Thread Synchronization

◼ Itis necessary to synchronize the activities of


the various threads
◼ all threads of a process share the same
address space and other resources
◼ any alteration of a resource by one thread
affects the other threads in the same
process
Types of Threads

User Level
Thread (ULT)
Kernel level
Thread (KLT)
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
ULTs
can run
Scheduling can be
on any
application specific
OS

Thread switching does not


require kernel mode
privileges
Disadvantages of ULTs
◼ Ina 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
Overcoming ULT
Disadvantages
Jacketing
• converts a blocking system call
into a non-blocking system call

Writing an application
as multiple processes
rather than multiple
threads
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
Advantages of KLTs
◼ The kernel can simultaneously schedule multiple
threads from the same process on multiple
processors
◼ If one thread in a process is blocked, the kernel
can schedule another thread of the same process
◼ Kernel routines can be multithreaded
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
Relationship Between
Threads and Processes

Table 4.2 Relationship between Threads and Processes


Applications That Benefit
◆ Multithreaded native applications
◆ characterized by having a small number of highly threaded processes.
Ex: Lotus Domino or Siebel CRM (Customer Relationship Manager)

◆ Multiprocess applications
◼ characterized by the presence of many single-threaded processes. Ex:
Oracle Data Base, SAP and PeopleSoft.

◆ Java applications
◆ Multiinstance applications
◼ multiple instances of the application in parallel
Processes and services provided by
the Windows Kernel are relatively
simple and general purpose
• implemented as objects
• created as new process or a copy of an existing
• an executable process may contain one or more
threads
• both processes and thread objects have built-in
synchronization capabilities
Relationship Between
Process and Resource
Process and Thread
Objects
Windows makes use of two types of
process-related objects:

Processes Threads

• an entity • a dispatchable
corresponding unit of work
to a user job or that executes
application that sequentially and
owns resources is interruptible
Windows Process and
Thread Objects
Windows Process Object
Attributes

Table 4.3 Windows Process Object Attributes


Windows Thread Object
Attributes

Table 4.4 Windows Thread Object Attributes


Multithreaded Process

Achieves concurrency
without the overhead of
using multiple processes

Threads within the same


Threads in different
process can exchange
processes can exchange
information through their
information through shared
common address space and
memory that has been set up
have access to the shared
between the two processes
resources of the process
Symmetric Multiprocessing
Support (SMP)

Threads of any
process can run Soft Affinity Hard Affinity
on any processor
• the dispatcher tries to • an application
assign a ready thread to the restricts thread
same processor it last ran execution to certain
on processors
• helps reuse data still in that
processor’s memory caches
from the previous
execution of the thread

You might also like