0% found this document useful (0 votes)
6 views4 pages

Emb Mod4 Threads

Uploaded by

katyaini1511
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)
6 views4 pages

Emb Mod4 Threads

Uploaded by

katyaini1511
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
You are on page 1/ 4

Threads

Threads and its types in Operating System


• Thread is a single sequence stream within a process. Threads have
same properties as of the process so they are called as light weight
processes. Threads are executed one after another but gives the
illusion as if they are executing in parallel. Each thread has different
states. Each thread has
• A program counter
• A register set
• A stack space
• Threads are not independent of each other as they share the code,
data, OS resources etc
Threads and Process

Similarities Differences
• Only one thread or • Threads are not
process is active at a independent,
time processes are.
• Within process both • Threads are designed
execute sequentially to assist each other,
• Both can create processes may or
children may not do it

Types of Threads
• User Level thread (ULT) –
Is implemented in the user level library, they are not created using the system
calls. Thread switching does not need to call OS and to cause interrupt to
Kernel. Kernel doesn’t know about the user level thread and manages them
as if they were single­threaded processes.
• Advantages of ULT –
• Can be implemented on an OS that doesn't support multithreading.
• Simple representation since thread has only program counter, register set, stack space.
• Simple to create since no intervention of kernel.
• Thread switching is fast since no OS calls need to be made.
• Disadvantages of ULT –
• No or less co­ordination among the threads and Kernel.
• If one thread causes a page fault, the entire process blocks
Types of Threads
• Kernel Level Thread (KLT) –
Kernel knows and manages the threads. Instead of thread table in each
process, the kernel itself has thread table (a master one) that keeps track of
all the threads in the system. In addition kernel also maintains the traditional
process table to keep track of the processes. OS kernel provides system call to
create and manage threads.
• Advantages of KLT –
• Since kernel has full knowledge about the threads in the system, scheduler may decide
to give more time to processes having large number of threads.
• Good for applications that frequently block.
• Disadvantages of KLT –
• Slow and inefficient.
• It requires thread control block so it is an overhead.

Switching
• In single threaded processes, the thread itself is the process. While in
multithreaded processes we need to switch between different th
• 1. Thread Switching :
Thread switching is a type of context switching from one thread to
another thread in the same process. Thread switching is very efficient
and much cheaper because it involves switching out only identities
and resources such as the program counter, registers and stack
pointers. The cost of thread­to­thread switching is about the same as
the cost of entering and exiting the kernel.reads for the execution of
our program.
Switching
• 2. Process Switching :
Process switching is a type of context switching where we switch one
process with another process. It involves switching of all the process
resources with those needed by a new process. This means switching
the memory address space. This includes memory addresses, page
tables, and kernel resources, caches in the processor.

Switching
TCS occurs when the CPU saves the current state of the thread and
switches to another thread of the same process.
PCS occurs when the operating system’s scheduler saves the current
state of the running Program (including the state of PCB) and switches
to another program.

You might also like