User level thread and Kernel level thread - CodeTextPro


User level thread & Kernel level thread

User level thread & Kernel level thread:
These are two main ways to implement thread: in user space and in the kernel.

User level thread: This type of threads loaded entirely in user space, kernel knows nothing about them. When threads are managed in user space, each process needs its own private thread table, the thread table consist of program counter, stack pointer, registers, state etc. The thread table is managed by run time system. Creating a new thread, switching between threads, and synchronizing threads are done via procedure call. i.e no kernel involvement. User-Level threads are hundred times faster than Kernel-Level threads.

User level thread Advantages:
  1. The most obvious advantage of this technique is that a user-level threads package can be implemented on an Operating System that does not support threads.
  2. User-level threads does not require modification to operating systems.
  3. Simple Representation: Each thread is represented simply by a PC, registers, stack and a small control block, all stored in the user process address space.
  4. Simple Management: This simply means that creating a thread, switching between threads and synchronization between threads can all be done without intervention of the kernel.
  5. Fast and Efficient: Thread switching is not much more expensive than a procedure call.

User level thread Disadvantages:
  1. User-Level threads are not a perfect solution as with everything else, they are a trade off. Since, User-Level threads are invisible to the OS they are not well integrated with the OS. As a result, Operating system can make poor decisions like scheduling a process with idle threads, blocking a process whose thread initiated an I/O even though the process has other threads that can run and scheduling a process with a thread holding a lock. Solving this requires communication between kernel and user-level thread manager.
  2. There is a lack of coordination between threads and operating system kernel. Therefore, process as whole gets one time slice irrespective of whether process has one thread or 1000 threads within. It is up to each thread to relinquish control to other threads.
  3. User-level threads requires non-blocking systems call i.e., a multithreaded kernel. Otherwise, entire process will blocked in the kernel, even if there are runnable threads left in the processes. For example, if one thread causes a page fault, the process blocks.

Kernel level thread: In kernel level threads the kernel does total work of thread movement. The kernel has a thread table that keeps track of all the threads in system. When a thread wants to create a new thread or destroy any existing thread, it makes a Kernel call, which takes the action.

Kernel level thread Advantages:
  1. Because kernel has full knowledge of all threads, Scheduler may decide to give more time to a process having large number of threads than process having small number of threads.
  2. Kernel-level threads are especially good for applications that frequently block.

Kernel level thread Disadvantages:
  1. The kernel-level threads are slow and inefficient. For instance, threads operations are hundreds of times slower than that of user-level threads.
  2. Since kernel must manage and schedule threads as well as processes. It require a full thread control block (TCB) for each thread to maintain information about threads. As a result there is significant overhead and increased in kernel complexity.

Difference between Process & Thread:

  1. Process is heavy weight or resource intensive.
  2. Process switching needs interaction with operating system.
  3. In multiple processing environments, each process executes the same code but has its own memory and file resources.
  4. If one process is blocked, then no other process can execute until the first process is unblocked.
  5. Multiple processes without using threads use more resources.
  6. In multiple processes each process operates independently of the others.

  1. Thread is light weight, taking lesser resources than a process.
  2. Thread switching does not need to interact with operating system.
  3. All threads can share set of open files, child processes.
  4. While one thread is blocked and waiting, a second thread in the same task can run.
  5. Multiple threaded processes use fewer resources.
  6. One thread can read, write or change another thread's data.

Post a Comment