Threading in Operating System

In this tutorial, we will learn about threading in the operating system, the benefits of multithread programming, and multithread models. By Abhishek Kataria Last updated : May 07, 2023

What is a thread in operating system?

A thread is a unit of CPU utilization, which comprises the following parts that are program counter, register set, stack and a thread ID. Generally, it's well known that the process is heavy weighted which means they consume lot more resources than the threads, and in this threads are light weighted.

What are the types of threading process?

Basically, there are two types of threading process are there which are as follows:

1. Single Threaded Process

Traditionally if a process has a single thread of control then it is termed as a single threaded process.

2. Multi Threaded Process

If a process has multiple threads of control then it is termed as a Multithreaded process. It can be used to perform multiple tasks at a single time.

Single and Multi Threaded process

Thread also plays a vital role in RPC which means Remote procedure call. It is used to call a function of some another program. The thread can also be used for the interprocess communication.

What are the benefits of multi-threaded programming?

1. Responsiveness

Since multithreading is an application which will allow a program to run even when a part of it is blocked. So it will increase the responsiveness to the particular user. For example suppose that a particular section is not responding in the above Multi-Threaded diagram instead of an entire process not responding, the two sections can respond to the user, which means Responsiveness.

2. Resource Sharing

It is a beneficial part in case of Multi-Threaded programming as it allows an application to have several different threads of venture within the same address space.

3. Boom Throughput

Number of jobs completed per unit time is increased which is a favorable condition.

4. Communication

As different threads have the same address space so it is very easier to communicate with the Multiple-Thread.

5. Economy

As we know that threads share resources of the process for which they belong, by this it will be more economical to create threads for data and resource sharing.

6. Utilization of the Multiprocessor Architectures

The benefits of Multi-Threading can be increased in an architecture which means threads can be made to run in parallel on a different processor, thus there will increment in a concurrency level.

Multithreading Models

Generally, there are two types of threads which are user thread and another one is kernel thread. In this type of system, the user-level threads are supported above the kernel and managed without kernel support, whereas kernel threads are directly supported and managed by the help of an operating system. On the basis of it there are generally three types of model governed:

1. Many to One Model

In this mapping is done between the many user-level threads to the one kernel thread. So in this, we have many user levels which are mapped with one kernel thread.

Many to One model in OS

2. One to One Model

In this mapping is done between each user thread and the kernel thread.

One to One Model in OS

3. Many to Many Model

It is a type of model in which it multiplexes many user-level threads to a smaller or equal number of kernel threads. In this, if we have four user threads than we can have either four or less than four kernel thread.

Many to Many Model in OS



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.