- OS - Home
- OS - Overview
- OS - History
- OS - Evolution
- OS - Functions
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- Process Management
- Processes in Operating System
- States of a Process
- Process Schedulers
- Process Control Block
- Operations on Processes
- Process Suspension and Process Switching
- Process States and the Machine Cycle
- Inter Process Communication (IPC)
- Context Switching
- Threads
- Types of Threading
- Multi-threading
- System Calls
- Scheduling Algorithms
- Process Scheduling
- Types of Scheduling
- Scheduling Algorithms Overview
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithm
- HRRN Scheduling Algorithm
- Priority Scheduling Algorithm
- Multilevel Queue Scheduling
- Lottery Scheduling Algorithm
- Starvation and Aging
- Turn Around Time & Waiting Time
- Burst Time in SJF Scheduling
- Process Synchronization
- Process Synchronization
- Solutions For Process Synchronization
- Hardware-Based Solution
- Software-Based Solution
- Critical Section Problem
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Mutual Exclusion Using Interrupt Disabling
- Peterson's Algorithm
- Dekker's Algorithm
- Bakery Algorithm
- Semaphores
- Binary Semaphores
- Counting Semaphores
- Mutex
- Turn Variable
- Bounded Buffer Problem
- Reader Writer Locks
- Test and Set Lock
- Monitors
- Sleep and Wake
- Race Condition
- Classical Synchronization Problems
- Dining Philosophers Problem
- Producer Consumer Problem
- Sleeping Barber Problem
- Reader Writer Problem
- OS Deadlock
- Introduction to Deadlock
- Conditions for Deadlock
- Deadlock Handling
- Deadlock Prevention
- Deadlock Avoidance (Banker's Algorithm)
- Deadlock Detection and Recovery
- Deadlock Ignorance
- Resource Allocation Graph
- Livelock
- Memory Management
- Memory Management
- Logical and Physical Address
- Contiguous Memory Allocation
- Non-Contiguous Memory Allocation
- First Fit Algorithm
- Next Fit Algorithm
- Best Fit Algorithm
- Worst Fit Algorithm
- Buffering
- Fragmentation
- Compaction
- Virtual Memory
- Segmentation
- Buddy System
- Slab Allocation
- Overlays
- Free Space Management
- Locality of Reference
- Paging and Page Replacement
- Paging
- Demand Paging
- Page Table
- Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Belady's Anomaly
- Thrashing
- Storage and File Management
- File Systems
- File Attributes
- Structures of Directory
- Linked Index Allocation
- Indexed Allocation
- Disk Scheduling Algorithms
- FCFS Disk Scheduling
- SSTF Disk Scheduling
- SCAN Disk Scheduling
- LOOK Disk Scheduling
- I/O Systems
- I/O Hardware
- I/O Software
- I/O Programmed
- I/O Interrupt-Initiated
- Direct Memory Access
- OS Types
- OS - Types
- OS - Batch Processing
- OS - Multiprocessing
- OS - Hybrid
- OS - Monolithic
- OS - Zephyr
- OS - Nix
- OS - Linux
- OS - Blackberry
- OS - Garuda
- OS - Tails
- OS - Clustered
- OS - Haiku
- OS - AIX
- OS - Solus
- OS - Tizen
- OS - Bharat
- OS - Fire
- OS - Bliss
- OS - VxWorks
- OS - Embedded
- OS - Single User
- Miscellaneous Topics
- OS - Security
- OS Questions Answers
- OS - Questions Answers
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Types of Threading in Operating System
In operating system, threads are single sequence stream within a process also known as lightweight processes. Threads are used to achieve parallelism by dividing a process into multiple threads of independent path of execution while sharing the same common memory, space, and resource. For example: tabs of a web browser.
An operating System is divided into two spaces: User Space and Kernel Space. Based on these two spaces, threads can be classified into two types as shown in the image below −
Types of Threads
There are two types of threads that are mentioned below −
User Level Threads
ULTs or User-level threads are implemented in user space by thread libraries. In this, the kernel is not aware of ULTs. Kernel manages them just like a single threaded processes. In this space, operations like thread creation, scheduling, synchronization is done.
User-level threads are small and much faster than kernel level threads. They are represented by a program counter(PC), stack, registers and a small process control block. Also, there is no kernel involvement in synchronization for user-level threads. Examples of user-level thread: POSIX Pthreads, Java green threads, GNU Portable Threads (GNU Pth), etc.
Advantages of User Level Thread
The advantages of user-level threads are as follows −
- User level threads are easier and faster to create and manage than kernel-level threads.
- Faster thread switching as there is no involvement of Kernel.
- User level thread can run on any operating system.
- Scheduling can be application specific in the user level thread.
Disadvantages of User Level Thread
The disadvantages of user-level threads are given below −
- Multithreaded applications in user-level threads cannot use multiprocessing to their advantage.
- If one user-level thread performs blocking operation then the entire process is blocked.
Kernel Level Threads
The kernel directly manages KLTs(Kernel-level threads) and supported directly by the operating system. Any application can be programmed to be multithreaded. All of the threads within an application are supported within a single process. The kernel maintains thread information and also performs operations like thread creation, scheduling, and management. In this space, the kernel is aware of all threads in the system unlike ULTs.
The context information for the process as well as the process threads is all managed by the kernel. The thread Scheduling by the Kernel is done on a thread basis. Because of this, kernel-level threads are slower than user-level threads. Examples of kernel-level thread: Windows threads, Linux threads, Solaris threads, Video games, etc.
Advantages of Kernel Level Thread
The advantages of kernel level threads are mentioned below −
- Kernel can simultaneously schedule multiple threads from the same process on multiple processes.
- If one thread in a process is blocked, the Kernel can schedule another thread of the same process.
- Kernel routines themselves can be multithreaded.
Disadvantages of kernel Level Thread
The disadvantages of kernel level threads are given below −
- Kernel threads are generally slower to create and manage than the user threads.
- Transfer of control from one thread to another within the same process requires a mode switch to the Kernel.
Difference Between User Level and Kernel Level Thread
The differences between user level and kernel level threads are given below −
| User Level Thread | Kernel Level Thread |
|---|---|
| It is lightweight and simple to implement. | It is heavyweight and more complex to implement than user level thread. |
| User level threads are managed without kernel support. | Kernel level threads are managed and supported directly by the operating system. |
| Kernel is not aware of user threads. | Kernel is fully aware and manages threads. |
| User level threads are faster to create and manage. | Kernel level threads are slower to create and manage. |
| User level threads cannot take advantage of multiprocessing. | Kernel level threads can take advantage of multiprocessing. |
| If one user level thread performs blocking operation, the entire process is blocked. | If one kernel level thread performs blocking operation, other threads in the same process can continue to execute. |
| There is low overhead in this. | High overhead because of system calls |
| Thread scheduling is done using thread library(user-level scheduler). | Thread scheduling is done by OS kernel scheduler |
| There is no need of system calls for thread operations | It needs system calls for thread operations |
| It is better for thread switching. | It is better for blocking operations. |
Conclusion
In operating systems, threads are of two types: User Level Threads (ULTs) and Kernel Level Threads (KLTs). User Level Threads (ULTs) are lightweight, faster to create, and are managed in user space but they are not good for multiprocessing and the entire process gets blocked if one thread is blocked. Kernel Level Threads (KLTs) are managed by the kernel, and is suitable for multiprocessing and can independently execute threads in the same process. KLTs are complex and slower compared to ULTs.