0
4.0kviews
Compare processes and threads. Explain user and kernel level threads execution and need of light weight threads.

Similar questions

Differentiate between Process and Threads using proper examples.

1 Answer
2
51views
Parameter Process Threads
1.Definition In traditional operating systems the basic unit of CPU utilization is a process. In operating systems with facility, the basic unit of CPU utilization is a thread.
2.Parameters owned Each process has its own program counter, its own register states, its own stack and its own address space. Each thread of a process has its own program counter, its own register states and its own stack. But all the threads of a process share the same address space.
3.Protection Protection between processes is needed because different processes may belong to different users. Due to sharing of address space, there is no protection between the threads of a process.
4.Process Type Traditional processes are referred as heavyweight processes. Threads are referred to as lightweight processes
5.Resource sharing Resource sharing is less efficient in processes compared to threads. Resource sharing can be achieved more efficiently and naturally in threads.
6.Switching cost Switching between processes is costlier. Switching between threads is cheaper.
7.overhead Creating a new process causes more overhead. Creating a new thread causes less overhead then for processes.
  • Threads are usually provided in form of a thread package which contains operations to create, destroy and synchronize variables.
  • A thread package can be implemented either in user space or in the kernel. There are two approaches for this known as user-level and kernel-level.
  • In user-level approach, the user space consists of a runtime system that is a collection of threads management routines. Threads run on top of the runtime systems which are also managed by it. The runtime system keeps status of kernel in a status information table having one entry per head.

enter image description here

  • All calls of the threads package are implemented as calls to the runtime system procedures that perform certain functions such as thread switching.
  • It is cheap to create and destroy threads as administration is kept in users address space while switching thread context can be done with a few instructions. But invocation of a blocking system call blocks the entire process of all the threads. To overcome this kernel-level approach is used
  • In kernel-level approach no runtime is used and threads are manages by kernel.

enter image description here

  • The threads status information table is maintained within the kernel.
  • Calls that a thread are treated as system calls that trap to the kernel due to which the kernel selects another thread to run. The thread can be of same process or another so the existence of threads is known to kernels.
  • Kernel-level is very expensive as switching thread contexts and the operations have to be carried out by the kernel.

Reason for use of LWP

  • A solution to this is using a hybrid form of user-level and kernel level threads which is known as lightweight processes(LWP).

enter image description here

  • The thread package can be shared by multiple LWPs as each LWP can run its on thread.
  • Creating, destroying and synchronizing threads is cheaper and involves no kernel intervention.
  • A blocking system call does not block the entire process while applications do not need to know about the LWPs.
  • LWPs can be implemented in multiprocessor environment.
Please log in to add an answer.