gate study material for cse operating system tutorial notes

Threads in operating system

Threads in operating system play an important role in improving the overall performance. There are several benefits of using the threads. These benefits are discussed in this tutorial.

Multithreading is an important concept used by most of the operating system. Computer science students should have knowledge about threads and multithreading. Questions on multithreading are generally asked many time in interview or also in GATE(CS/IT) examination.

In this  threads in operating system based tutorial we will learns about several concepts of threads and multithreading environment. tem will discuss about threading concepts such as threads basic , its advantages, threads implementation in operating system , user level and kernel level threads.

 Frequently Asked Questions

By the end of this tutorial students got the answer of the following questions

  • What is thread in os?
  • Write difference between process and thread?
  •  What do you understand by thread control block?
  • What is program counter?
  • Different benefits of using thread.
  • Define multithreading.
  • What is User level thread?
  • What is kernel level thread?
  • Difference between kernel level and user level thread.
  • Benefits of user level and kernel level thread.

What is Thread in OS ?

A thread is a light weight process which can utilize the CPU independently. A thread meaning is just a flow of execution through its  process code or minimum unit of CPU utilization.

Process has a process control block in same way a thread has it’s thread control block. Thread control block keeps the information about that thread. Thread control block also has program counter field that keeps track of which instruction to execute next.

Each thread also has it’s own system registers. Working variables associated with a thread are stored in these system registers.

This is also important to note that threads in operating system also has a stack and this stack provides the information about the execution history of the thread.

The most important point to be noted about the thread is that a thread shares with its peer threads various information such as code segment, data segment, and open files.

Important points to remember about what is thread in os is that if one thread tries to alter a code segment memory item, then all other threads can see that.

Threads in os provide a method to improve application performance. This method is nothing but the use of parallelism.

Thread use parallelism or multi-threading concepts to improve performance of the application. Threads give a software based approach to reduce the overhead.

More than one thread belongs to exactly one process, and no thread can exist outside a process. Each thread represents a separate flow of control.

In the present time threading concepts is also successfully used in implementing network servers and web servers. They also provide a best support for parallel execution of applications using shared memory multiprocessors.

threads in operating system

Benefits of using Threads in Operating System

There are following advantages of threads in operating system

  • Thread helps in minimize the context switching overhead. Context switch time is less as compare to switching time among the processes.
  •  We can achieve concurrency or parallelism by using more than one threads in a single process.
  •  They provide efficient communication.
  •  It is more economical to create and context switch threads.
  •  It is easy to utilize the multiprocessor architectures using threads to a greater scale and efficiency.
  •  Threads implementation in operating system.

What is Thread in OS at User Level?

User level threads manage user threads it means thread related to user process. In this case, the thread management kernel does not have information about presence of threads.

The thread library is used to manage the user level thread this thread library Includes the code for the following purpose.

  • To create and destroy the threads.
  • To  pass messages and data among threads.
  • To  schedule   an execution of thread.
  • To  save and restore the thread contexts.

      Disadvantages of User Level Threads

  •          Most of the system calls are blocking call.
  •         Multi threaded application cannot take advantage of multiprocessing.

threads in operating system

Kernel Level Threads

These are the threads managed by operating system which are acting on a kernel, an operating system core. In case of kernel level threads, thread management is done by the Kernel. Thread management code in the application area  is not available here because Operating System directly supports to Kernel levels  threads.
   Here any application can be programmed to be multi threaded. All of the threads  are supported within a single process for an application. These threads share the same code , data and file of the process to which they belong.
    It is the responsibility of the kernel to  maintains context information for the process as a whole and for individuals threads within the process. Scheduling by the Kernel is done on a thread basis. The Kernel performs thread creation, scheduling, and management in Kernel space. Kernel threads are generally slower to create and manage than the user threads.

   Advantages of Kernel Level Threads

    There are following advantages of Kernel level threads 
  •     The Kernel can simultaneously schedule multiple threads from the same process on          multiple processes.
  •     One major advantage of kernel level thread is that If any one thread in a process is         blocked, then  Kernel is capable of scheduling a new thread for that process.
  •        Kernel routines themselves can be multi threaded.

Also Read – Best Books on Social Issues in India

Disadvantages of Kernel Level Threads:

  • Kernel threads are created and managed slowly as compare to user level threads.  
    Students can study the operating system tutorial here.

Conclusion and Summary

In this threads in operating system we have discussed the following points
  • Definition of what is thread in os.
  • Benefits of using thread.
  • Overview of Multithreading.
  • User level thread
  • Kernel level thread.
  • Difference between user level threads and kernel level threads.

Give your feedback or leave comment so that we can improve and provide you a good quality tutorials

If you find this threads in operating system tutorial page helpful in improving your software engineering concepts then please Like and Share the post on Facebook, Twitter, LinkedIn through their icons as given below.

Previous Tutorial – Process Management in OS

Next Tutorial –  Process Control Block

Leave a Reply

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