User level thread vs Kernel level thread in Operating System (OS)
Difference Between User Level and Kernel Level Threads
User Level Thread
Features of User Level Thread –
- Implemented by user and managed by run-time system (user-level library).
- OS is not aware of existence of threads.
- OS manages the user level threads as if they are single threaded process.
- Creation of thread switching between thread and synchronizing thread are all done via procedural call.
Advantage of User Level Thread-
- Are extremely fast and efficient, because the switching between thread takes almost same time as a procedural call.
- OS doesn’t need to interfere ,everything can be without it.
- They do not modify OS.
- Threads are cheap and fast at user level.
- User level thread can be implemented in OS, who do not implement threads.
Disadvantage of User Level Thread-
- Since OS isn’t aware of user level thread , scheduler does not schedule them properly. Eg -> Java thread, POSIX thread etc.
- If 1 user level thread performs blocking operation, entire process will be blocked.
Kernel Level Thread
Features of Kernel Level Thread –
- OS managed threads.
- OS knows about and manages the thread.
- Kernel has a thread table which keeps tracks of all threads in the system.
- System calls create and manage threads.
Advantages of Kernel Level Thread ->
- As kernel has full knowledge of threads, so scheduler handles the processes better.
- For application that frequently block, Kernel level threads are good.
Disadvantages of Kernel Level Thread ->
- Slow and inefficient than user level.
- Hardware support is needed.
- Context switching time is more. Eg – Window Solaris
- If 1 kernel thread performs blocking operation, then another thread can continue execution.
- Banker’s Algorithm
- bankers algorithm for deadlock avoidance in c (in above post itself)Resource Allocation Graph (RAG)
- Dining Philosopher’s Problem
- Bounded Buffer Problem / Producer Consumer Problem
- User Level thread Vs Kernel Level thread
- Multithreading models
- Difference between program and process