Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

What is Thread in Operating System

A thread refers to an execution unit in the process that has its own programme counter, stack, as well as a set of registers. Threads aren’t actually allowed to exist outside a process. Furthermore, each and every thread belongs to one single process. Multiple threads can easily communicate information and important data, such as code segments or files, as well as data segments.

In this article, we will look more into what is a thread in Operating Systems according to the GATE Syllabus for (Computer Science Engineering) CSE. Let us read ahead to find out more about it.

Table of Contents

What is Thread in Operating Systems?

A thread refers to a single sequential flow of activities being executed in a process; it is also known as the thread of execution or the thread of control. Now, thread execution is possible within any OS’s process. Apart from that, a process can have several threads. A distinct programme counter, a stack of activation records as well as control blocks are used by each thread of the same process. Thread is frequently described as a light technique.

what-is-thread-in-operating-system

The procedure can be easily broken down into numerous different threads. Multiple tabs in a browser, for example, can be considered threads. MS Word employs many threads to prepare the text in one thread, receive input in another thread, and so on.

Why Do We Need Thread?

  • Creating a new thread in a current process requires significantly less time than creating a new process.
  • Threads can share common data without needing to communicate with each other.
  • When working with threads, context switching is faster.
  • Terminating a thread requires less time than terminating a process.

Types of Threads

1. User-Level Thread

The user-level thread is ignored by the operating system. User threads are simple to implement and are done so by the user. The entire process is blocked if a user executes a user-level operation of thread blocking. The kernel-level thread is completely unaware of the user-level thread. User-level threads are managed as single-threaded processes by the kernel-level thread.

Threads in Java, POSIX, and other languages are examples.

Pros

  • User threads are easier to implement than kernel threads.
  • Threads at the user level can be used in operating systems that do not allow threads at the kernel level.
  • It is more effective and efficient.
  • Context switching takes less time than kernel threads.
  • It does not necessitate any changes to the operating system.
  • The representation of user-level threads is relatively straightforward. The user-level process’s address space contains the register, stack, PC, and mini thread control blocks.
  • Threads may be easily created, switched, and synchronised without the need for process interaction.

Cons

  • Threads at the user level are not coordinated with the kernel.
  • The entire operation is halted if a thread creates a page fault.

what-is-thread-in-operating-system

2. Kernel-Level Thread

The operating system is recognised by the kernel thread. Each thread and process in the kernel-level thread has its own thread control block as well as process control block in the system. The operating system implements the kernel-level thread. The kernel is aware of all threads and controls them. The kernel-level thread provides a system call for user-space thread creation and management. Kernel threads are more complex to build than user threads. The kernel thread’s context switch time is longer. The execution of the Banky thread can continue in case a kernel thread performs a blocking operation.

Solaris, for example.

what-is-thread-in-operating-system

Pros

  • All threads are completely aware of the kernel-level thread.
  • The scheduler may decide to devote extra CPU time to threads with large numerical values.
  • Applications that happen to block the frequency should use the kernel-level thread.

Cons

  • All threads are managed and scheduled by the kernel thread.
  • Kernel threads are more complex to build than user threads.
  • Kernel-level threads are slower than user-level threads.

Components of Threads

  1. Stack space
  2. Register set
  3. Program counter

Benefits of Threads

  • Enhanced system throughput: The number of jobs completed per unit time increases when the process is divided into numerous threads, and each thread is viewed as a job. As a result, the system’s throughput likewise increases.
  • Effective use of a Multiprocessor system: You can schedule multiple threads in multiple processors when you have many threads in a single process.
  • Faster context switch: The thread context switching time is shorter than the process context switching time. The process context switch adds to the CPU’s workload.
  • Responsiveness: When a process is divided into many threads, and each of them completes its execution, then the process can be responded to as quickly as possible.
  • Communication: Multiple-thread communication is straightforward because the threads use the same address space, while communication between two processes is limited to a few exclusive communication mechanisms.
  • Resource sharing: Code, data, and files, for example, can be shared among all threads in a process. Note that threads cannot share the stack or register. Each thread has its own stack and register.

Keep learning and stay tuned to get the latest updates on the GATE Exam along with Eligibility Criteria, GATE Syllabus for CSE (Computer Science Engineering), GATE CSE Notes, GATE CSE Question Paper, and more.

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*