Introduction to Threads in Operating Systems

undefined
 
Operating Systems
(CS 340 D)
 
 
 
Princess Nora University
Faculty of Computer & Information Systems
Computer science Department
undefined
 
 
(Chapter-4)
Threads
 
Chapter 4:  Threads
 
1.
Motivation
2.
Benefits
 
3
 
OBJECTIVES
:
 
To introduce the 
notion of a thread 
       a fundamental unit of CPU utilization that forms the basis of
multithreaded computer systems.
 
4
 
OVERVIEW
A 
thread
:  
is a basic unit of CPU utilization
 
(i.e. It
 
is the 
smallest
 sequence of programmed instructions that
can be managed 
independently)
Threads provide a way 
to improve application
performance
 through parallelism.
 
5
 
Thread comprises 
:
 
 
 
It
 
shares
 
with other threads 
belonging to the 
same process 
its :
code section,
data section
 other operating system resources
.
 
 
 
 
OVERVIEW (cont..)
 
6
 
A 
traditional
 (or 
heavyweight
) process has a 
single
 
thread of
control.
 
A thread could be considered a ‘
lightweight
’ process If a process
has 
multiple threads 
of control, it can 
perform more than one
task at a time.
 
Each
 
thread belongs to exactly
 
one
 
process and no thread can
exist outside a process.
 
 
OVERVIEW (cont..)
 
7
 
Single and Multithreaded Processes
 
n
Traditional ( heavyweight ) process 
has
a single thread of control - There is 
one
program counter, and 
one
 
sequence of
instructions that can be carried out at any
given time.
 
n
Multi-threaded applications 
have multiple
threads within a single process - Every thread
have their own
 
program counter, stack
and set of registers,
 but
 
sharing 
common
code, data, and certain structures such as
open files.
 
8
 
MOTIVATION
 
 
Many software packages that run on modern desktop PCs are
multithreaded.
 
An application typically is implemented as 
a separate process
with 
several threads 
of control.
 
E.G. (1) 
: 
A word processor 
may have :
o
a thread for displaying graphics,
o
a thread for responding to keystrokes from the user,
o
a third thread for spelling and grammar checking
 
9
 
MOTIVATION
 
E.G. (2) :  
A web server 
 
Multiple threads allow for 
multiple requests 
to be satisfied
simultaneously, 
without having to service requests sequentially or to
fork off (/create)  separate processes for every incoming
request….(creating a new thread belongs to an existing process is 
less
overhead 
of creating a new process)
 
Most operating system kernels are now multithreaded
 
several threads operate in the kernel, and each thread performs a specific task, such
as managing devices or interrupt handling.
 
10
 
BENEFITS
 
There are four major 
categories 
of benefits to multi-
threading:
 
 
1- Responsiveness
 
- 
One thread may provide 
rapid response
while other threads are blocked or slowed down doing intensive
calculations.
 
2- Economy 
- 
Creating and managing threads is 
much faster
than performing the same tasks for processes.
 
11
 
BENEFITS (cont..)
 
There are four major 
categories 
of benefits to multi-
threading:
 
3-Resource sharing 
 
Processes may only share resources through techniques (e.g.
shared memory or message passing) …Such techniques 
must
be explicitly 
arranged by the programmer.
By default 
threads share common code, data, and other
resources, which allows multiple tasks to be performed
simultaneously in 
a 
single address space.
 
12
 
 
4- Scalability
 
The benefits of multithreading can be greatly increased in a
multiprocessor architecture, where 
threads may be running
in parallel 
on different processors.
 
A 
single-threaded process 
can only run on one
processor, regardless how many CPUs are available.
Note that single threaded processes can still benefit from multi-
processor architectures when there are multiple processes
contending for the CPU
 
BENEFITS (cont..)
 
13
undefined
 
Thank you
 
End of
Chapter 4
 
14
Slide Note
Embed
Share

This content delves into the concept of threads in operating systems, highlighting their role as fundamental units of CPU utilization. Threads enhance application performance through parallelism, sharing resources within a process and enabling multitasking capabilities. The discussion covers the structure of threads, distinguishing between traditional heavyweight processes and modern multithreaded applications. Additionally, it elaborates on the motivation behind utilizing threads in software development, emphasizing the prevalence of multithreaded applications in modern computing environments.

  • Operating Systems
  • Threads
  • CPU Utilization
  • Multithreading
  • Software Development

Uploaded on Mar 03, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Princess Nora University Faculty of Computer & Information Systems Computer science Department Operating Systems (CS 340 D)

  2. (Chapter-4) Threads

  3. Chapter 4: Threads 1. Motivation 2. Benefits 3

  4. OBJECTIVES: To introduce the notion of a thread a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems. 4

  5. OVERVIEW A thread: is a basic unit of CPU utilization (i.e. Itis the smallest sequence of programmed instructions that can be managed independently) Threads provide a way to improve application performance through parallelism. 5

  6. OVERVIEW (cont..) Thread comprises : ID program counter register set stack It shares with other threads belonging to the same process its : code section, data section other operating system resources. 6

  7. OVERVIEW (cont..) A traditional (or heavyweight) process has a single thread of control. A thread could be considered a lightweight process If a process has multiple threads of control, it can perform more than one task at a time. Each thread belongs to exactly one process and no thread can exist outside a process. 7

  8. Single and Multithreaded Processes Traditional ( heavyweight ) process has a single thread of control - There is one program counter, and one sequence of instructions that can be carried out at any given time. Multi-threaded applications have multiple threads within a single process - Every thread have their own program counter, stack and set of registers, but sharing common code, data, and certain structures such as open files. 8

  9. MOTIVATION Many software packages that run on modern desktop PCs are multithreaded. An application typically is implemented as a separate process with several threads of control. E.G. (1) : A word processor may have : o a thread for displaying graphics, o a thread for responding to keystrokes from the user, o a third thread for spelling and grammar checking 9

  10. MOTIVATION E.G. (2) : A web server Multiple threads allow for multiple requests to be satisfied simultaneously, without having to service requests sequentially or to fork off (/create) separate processes for every incoming request .(creating a new thread belongs to an existing process is less overhead of creating a new process) Most operating system kernels are now multithreaded several threads operate in the kernel, and each thread performs a specific task, such as managing devices or interrupt handling. 10

  11. BENEFITS There are four major categories of benefits to multi- threading: 1- Responsiveness - One thread may provide rapid response while other threads are blocked or slowed down doing intensive calculations. 2- Economy - Creating and managing threads is much faster than performing the same tasks for processes. 11

  12. BENEFITS (cont..) There are four major categories of benefits to multi- threading: 3-Resource sharing Processes may only share resources through techniques (e.g. shared memory or message passing) Such techniques must be explicitly arranged by the programmer. By default threads share common code, data, and other resources, which allows multiple tasks to be performed simultaneously in a single address space. 12

  13. BENEFITS (cont..) 4- Scalability The benefits of multithreading can be greatly increased in a multiprocessor architecture, where threads may be running in parallel on different processors. A single-threaded process can only run on one processor, regardless how many CPUs are available. Note that single threaded processes can still benefit from multi- processor architectures when there are multiple processes contending for the CPU 13

  14. Thank you End of Chapter 4 14

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#