Threads in Operating System

Operating System

Threads in Operating Systems



Threads in Operating Systems are operating routes inside a method. A process may contain many threads.

The lightweight method is also known as a chain. The theory is to split a cycle into several threads to create parallelism. For examples, several tabs may be separate threads inside a window. MS Word uses several threads: one for encoding the file, another for storing inputs, etc.


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:  f the process is divided into multiple threads, if one thread completes its execution, then its output can be immediately returned.


  1. Faster context switch: Context switch time between threads is lower compared to process context switch. Process context switching requires more overhead from the CPU.


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


  1. Resource sharing: Resources like code, data, and files can be shared among all threads within a process.


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


Note: stack and registers can’t be shared among the threads. Each thread has its own stack and registers.


Types of Threads:

There are two types of Threads.

  1. User-Level Threads
  2. Kernel-Level Threads


Kernel-Level Thread:

Kernel-level threads are managed explicitly by the operating system, and the kernel handles the process. Both the task history knowledge and machine threads are both handled by the kernel. Regardless of that, threads at the kernel level are slower than threads at the user level. To make performance easier, the process’s operation component is divided into threads. As such, the App now handles the processes and threads. All thread operations are performed in the kernel, and all threads in the device are controlled by the OS. Threads handled by OS are considered kernel-level threads, or processes of light weight.

In this process the threads are known to and handled by the kernel. In this case, no run-time device is needed. The kernel has a thread table instead of a thread table in each process which keeps track of all threads in the system. Furthermore, the kernel holds the standard phase table to maintain control of operations. The kernel operating systems include a system call for the development and control of threads.


Examples – virtually all general purpose operating systems, including:


  • Windows
  • Solaris
  • Linux
  • Tru64 UNIX
  • Mac OS X



Advantages of Kernel-Level Thread:


  1. Since the kernel has full awareness of all threads, Scheduler may agree to offer a loop with a large number of threads more time than a loop with a limited number of threads in it.
  2. Kernel-level threads are especially useful for programs that often block.
  3. Multiple threads in the same operation may be implemented in kernel-level threads on separate processors.
  4. It is easy to multithread the kernel routines too.
  5. If a kernel-level thread is blocked, the kernel can program another thread of the same method.



Windows Thread:


  • Windows implements the Windows API – primary API for Win 98, Win NT, Win 2000, Win XP, and Wi54n 7.
  • Implements the one-to-one mapping, kernel-level.
  • Each thread contains
  • A thread id
  • Register set representing state of processor
  • Separate user and kernel stacks for when thread runs in user mode or kernel mode
  • Private data storage area used by run-time libraries and dynamic link libraries (DLLs)
  • The register set, stacks, and private storage area are known as the context of the thread
  • The primary data structures of a thread include:
  • ETHREAD (executive thread block) – includes pointer to process to which thread belongs and to KTHREAD, in kernel space
  • KTHREAD (kernel thread block) – scheduling and synchronization info, kernel-mode stack, pointer to TEB, in kernel space
  • TEB (thread environment block) – thread id, user-mode stack, thread-local storage, in user space


Visit this link for more on Operating Systems.

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *