0% found this document useful (0 votes)
34 views16 pages

OSChapter 3

The document provides an overview of threads, defining them as lightweight processes that share memory space within a process, allowing for more efficient execution compared to traditional processes. It discusses the advantages of multithreading, including responsiveness, resource sharing, and scalability, as well as different threading models such as many-to-one, one-to-one, and many-to-many. Additionally, it highlights the types of threads, including user-level and kernel-level threads, and their respective management systems.

Uploaded by

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

OSChapter 3

The document provides an overview of threads, defining them as lightweight processes that share memory space within a process, allowing for more efficient execution compared to traditional processes. It discusses the advantages of multithreading, including responsiveness, resource sharing, and scalability, as well as different threading models such as many-to-one, one-to-one, and many-to-many. Additionally, it highlights the types of threads, including user-level and kernel-level threads, and their respective management systems.

Uploaded by

hirpaadugna1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

ap te r T h r ee

Ch
Th r ea d s

04/23/2025 1
Contents
• Definition
• Thread vs process
• Thread advantage
• Single vs multithread
• Why thread
• Thread types

04/23/2025 2
THREAD…
• A thread refers to a single sequential flow of activities being
executed in a process
• A thread is a lightweight process as it possesses some of the
properties of process (states + scheduling + register + program
counter + stack space…)
• For example, in a browser, multiple tabs can be different threads.
MS Word uses multiple threads: one thread to format the text,
another thread to process inputs, etc.
• Most modern applications are multithreaded
• Threads run within application
• Process creation is heavy-weight while thread creation is light-
weight (why?) Discuss
04/23/2025 3
Why thread is lightweight…
• Thread uses fewer resources compared to process
• Threads share the same address space but processes
cannot
• Context switch among threads is fast compared to
that of context switch for process (switching is time
consuming in process)
• Thread termination is less time

04/23/2025 4
Difference Between Process and
Thread
• The primary difference is that threads within the same process
run in a shared memory space, while processes run in separate
memory spaces.
• Threads are not independent of one another like processes are,
and as a result, threads share with other threads their code
section, data section, hence no inter-process
communication.
• Thread allows multiple executions to take place in the same
process environment, called multithreading but processes
executed in different environment.
• similarity of thread and process are, like process, a thread has
its own program counter (PC), register set, and stack space.
04/23/2025 5
Web server request

04/23/2025 6
Benefits
• Responsiveness – may allow continued execution if
part of process is blocked, especially important for user
interfaces
• Resource Sharing – threads share resources of
process, easier than shared memory or message
passing
• Economy – cheaper than process creation, thread
switching lower overhead than context switching
• Scalability – process can take advantage of
multiprocessor architectures
04/23/2025 7
Single and Multithreaded Processes

04/23/2025 8
(a) Three processes each with one thread.
(b)One process with three threads each thread has a
program counter, registers stack, and state; but all
threads of a process share address space, global
variables and other resources such as open files,
etc.

04/23/2025 9
• The first column lists some items
shared by all threads in a process.
• The second one lists some items
private to each thread.

04/23/2025 10
Threads-usage :-Why we do need
threads?
• Simplifying the programming model since many
activities are going on at once.
• They are easier to create and destroy than processes
since they don't have any resources attached to them
• Performance improves by overlapping activities if there
is too much I/O
• Real parallelism is possible if there are multiple CPUs
• Note: implementation details are beyond the scope of
the course (distributed systems).

04/23/2025 11
Threads-usage :-Why we do need
threads?
• E.g., a word processor has different parts; parts for
• Interacting with the user
• Formatting the page as soon as the changes are made
• Timed savings (for auto recovery)
• Spelling and grammar checking

04/23/2025 12
Multithreading Models
Many-to-One
 Many user-level threads mapped to
single kernel thread
 One thread blocking causes all to block
 Multiple threads may not run in parallel
on multi-core system because only one
may be in kernel at a time
 Few systems currently use this model
 Examples:
 Solaris Green Threads
 GNU Portable Threads

04/23/2025 13
Types of thread
• User level threads - management done by user-level threads library,
kernel knows nothing about them
• Three primary thread libraries:
• POSIX Pthreads
• Windows threads
• Java threads
• Kernel level threads - Supported by the Kernel
• Examples – virtually all general purpose operating systems, including:
• Windows
• Solaris
• Linux
• Tru64 UNIX
• Mac OS X

04/23/2025 14
One-to-One
• Each user-level thread maps to
kernel thread
• Creating a user-level thread creates
a kernel thread
• More concurrency than many-to-one
• Number of threads per process
sometimes restricted due to
overhead
• Examples
• Windows
• Linux
• Solaris 9 and later

04/23/2025 15
Many-to-Many Model

• Allows many user level


threads to be mapped to
many kernel threads
• Allows the operating
system to create a
sufficient number of
kernel threads
• Solaris prior to version 9
• Windows with the
ThreadFiber package

04/23/2025 16

You might also like