Emb Mod4 Threads
Emb Mod4 Threads
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 singlethreaded 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 coordination 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 threadtothread 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.