Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Operating System  >  Threads & Its Types - User Level Thread & Kernel Level Thread

Threads & Its Types - User Level Thread & Kernel Level Thread | Operating System - Computer Science Engineering (CSE) PDF Download

Thread in Operating System

What is a Thread?
A thread is a path of execution within a process. A process can contain multiple threads.

Process vs 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, and OS resources (like open files and signals). But, like process, a thread has its own program counter (PC), register set, and stack space.

Advantages of Thread over Process

  1. Responsiveness: If the process is divided into multiple threads, if one thread completes its execution, then its output can be immediately returned.
  2. Faster context switch: Context switch time between threads is lower compared to process context switch. Process context switching requires more overhead from the CPU.
  3. Effective utilization of multiprocessor system: If we have multiple threads in a single process, then we can schedule multiple threads on multiple processor. This will make process execution faster.
  4. Resource sharing: Resources like code, data, and files can be shared among all threads within a process.
    Note: stack and registers can’t be shared among the threads. Each thread has its own stack and registers.
  5. Communication: Communication between multiple threads is easier, as the threads shares common address space. while in process we have to follow some specific communication technique for communication between two process.
  6. Enhanced throughput of the system: If a process is divided into multiple threads, and each thread function is considered as one job, then the number of jobs completed per unit of time is increased, thus increasing the throughput of the system.

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

  1. A program counter
  2. A register set
  3. A stack space

Threads are not independent of each other as they share the code, data, OS resources etc.

Similarity between Threads and Processes

  1. Only one thread or process is active at a time
  2. Within process both execute sequentiall
  3. Both can create children

Differences between Threads and Processes

  1. Threads are not independent, processes are.
  2. Threads are designed to assist each other, processes may or may not do it

Types of Threads

There are two types of threads.

  1. User Level Thread
  2. Kernel Level Thread

1. 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.

(i) Advantages of ULT

  • Can be implemented on an OS that does’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.

(ii) Disadvantages of ULT

  • No or less co-ordination among the threads and Kernel.
  • If one thread causes a page fault, the entire process blocks.

2. 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.

(i) 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.

(ii) Disadvantages of KLT

  • Slow and inefficient.
  • It requires thread control block so it is an overhead.

Difference between User Level thread and Kernel Level thread

Threads & Its Types - User Level Thread & Kernel Level Thread | Operating System - Computer Science Engineering (CSE)Threads & Its Types - User Level Thread & Kernel Level Thread | Operating System - Computer Science Engineering (CSE)

The document Threads & Its Types - User Level Thread & Kernel Level Thread | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

study material

,

ppt

,

mock tests for examination

,

pdf

,

Sample Paper

,

MCQs

,

Exam

,

Threads & Its Types - User Level Thread & Kernel Level Thread | Operating System - Computer Science Engineering (CSE)

,

Previous Year Questions with Solutions

,

Semester Notes

,

Summary

,

Viva Questions

,

Objective type Questions

,

video lectures

,

shortcuts and tricks

,

Threads & Its Types - User Level Thread & Kernel Level Thread | Operating System - Computer Science Engineering (CSE)

,

past year papers

,

Important questions

,

Extra Questions

,

Free

,

Threads & Its Types - User Level Thread & Kernel Level Thread | Operating System - Computer Science Engineering (CSE)

,

practice quizzes

;