Threads

Threads:-

 Thread is a sequential flow of tasks within a process. Threads in OS can be of the same or different types. Threads are used to increase the performance of the applications.

       Each thread has its own program counter, stack, and set of registers. But the threads of a single process might share the same code and data/file. Threads are also termed lightweight processes as they share common resources.


Components of Thread:-

A thread has the following three components:

  1. Program Counter
  2. Register Set
  3. Stack space

Why do you need Threads?

Threads in the operating system provide multiple benefits and improve the overall performance of the system. Some of the reasons threads are needed in the operating system are:

  • Since threads use the same data and code, the operational cost between threads is low.
  • Creating and terminating a thread is faster compared to creating or terminating a process.
  • Context switching is faster in threads compared to processes.

Advantages of Threading:-

  • Threads improve the overall performance of a program.
    • Threads increase the responsiveness of the program
    • Context Switching time in threads is faster.
    • Threads share the same memory and resources within a process.
    • Communication is faster in threads.
    • Threads provide concurrency within a process.
    • Enhanced throughput of the system.
    • Since different threads can run parallelly, threading enables the utilization of the multiprocessor architecture to a greater extent and increases efficiency.

    Thread API Notes:- Click Here

                        This Pdf will definitely help you to understand thoroughly of the concepts in Thread API.