ARTICLE: Operating System: Multithreading Explained in Simple Words

The concept of the multithreading begins with the definition of the thread.

WHAT IS A THREAD?

The flow of the execution of the process through its code and keeping track of its program counter keep an eye on the set of instructions which will execute next. In this flow, the system also keeps track of the stacks which the execution history contains and the system registers which hold its current working variables. The code segment, the data segment, and the open files are a few sectors of information which the thread shares. Changes made by one thread are seen by the rest. For instance, when a thread modifies the data segment item, the other threads can see it.

The other name of threads is a lightweight process. One way to improve the performance of the application through parallelism is with the help of threads. It is because there is various software approach for the improvement of the operating system’s performance. One of them is through the reduction of the overhead thread who has the value equal to the classical process.

There is one thread for exactly one process. But there is no existence of any thread outside the process. The flow of control for every thread is different. They are used in the execution of the network servers and the web server. It always brings success in the task. The threads are helpful in providing suitable information for the implementation of the applications on the shared-memory multiprocessors in the parallel format.

Let us now talk about the differences between the process and thread

  1. Weight and intensiveness-

Process- It is heavy and needs resources in the intensive form.

Thread- As compared to the process, a thread is lightweight. Also, it takes lesser number of resources.

 

  1. Interaction with the operating system-

Process- There is a need for the integration with the operating system for the process switching.

Thread- But, it is opposite in case of threads. They don’t need to interact with the operating system.

 

  1. Execution

Process- There is the execution of the same code in the multiple processing environments. But, for this processes need own memory and file resources.

Thread- The threads can share the all the open files.

 

  1. Blocking technique-

Process- No other process is allowed to be executed if one of the processes is blocked. It will not happen until there is the unblocking of the previous process.

Thread- This trait works oppositely to the threads. When a thread gets blocked, the others are being normally executed. The other threads can run in the same task.

 

  1. Multiplicity-

Process- There is the usage of more resources by the multiple processes without using threads.

Thread- There is the usage of fewer resources by the multiple threaded processes.

 

  1. Independence-

Process- There is the independence of every process in the operation of the multiple processes.

Thread- One thread can change, read and write the data of the other thread.

 

Benefits of the threads

  1. They are responsible for the minimization of the context switching time.
  2. Result in the effectiveness of the communication.
  3. Using a thread can result in the concurrency in the process.
  4. Helps is making the creation and the context switching threads economically.
  5. Hike in the utilization of the multiprocessor and the architectures.
  6. Enhancement of the scaling and the efficiency of the multiprocessor.

TYPES OF THREAD

There are two ways in which we can implement the threads are as follows-

  1. User Level Threads- The user manages these threads.
  2. Kernel Level Threads- The operating system act on a kernel which is the operating system manages the core of the operating system.

Let us talk about the types of the thread briefly one by one.

  1. User level threads- Under this type of threads, there is no knowledge of the existence of the threads to the kernel. Code for the creation as well as to destroy the threads and passing a message is one of the critical components of the thread library. The other elements of the library are the availability of the data between the threads. It is required to save and restore the thread contexts and schedule the thread execution. Only one thread can start the application.

Perks of using the user-level threads

  1. No requirement of the kernel mode privileges.
  2. Creation and the management of the user level threads do not need much time.
  3. Compatibility with every operating system.
  4. The user level thread has high application specification.

Detriments of the user-level threads

  1. There is the blockage of the calls in the typical operating system.
  2. In the multiprocessing items, there is no way to take advantage of the multithreaded application.
  3. Kernel-level threads-

As the name itself specifies, the kernels manage the threads. The type of the thread management technique experiences an absence of the code in the area of the application. The operating system directly supports the kernel threads in the kernel level threads. We can program an application and make it multithreaded. In such form, only a single process can assist the threads.

Maintaining the context information for the process as a whole is the duty of the kernels. It also includes the individual threads in the process. The thread basis is opted for the scheduling process by the core.

FUNCTIONS OF THE KERNEL-

  1. Creation of the threads
  2. Schedules threads in the kernel space
  3. Takes care of the management of the threads in the kernel space.

But they are slow in the creation and the management of the threads as compared to the user threads.

Perks of the kernel level threads

  1. It saves time by scheduling the threads simultaneously from the same process on their multiple parts.
  2. The kernels which routine themselves can perform multiple threading.
  3. The kernel can re-schedule one thread of the same process if the process has experienced the blockage of one thread.

Detriments of the type of the thread managing technique

  1. Takes more time to create and manage the user threads.
  2. Control the transfer of one thread to another. It takes place within the same process, and for this, it needs a mode switch to the kernel.

MULTITHREADING MODELS

There is the facility of getting a combined user-level thread and kernel level thread. Some of the operating systems provide this. For example, Solaris is one of the instances of an OS made with the combined approach.

Three types of the multithreading models are as follows-

  1. Many-to-many relationship
  2. Many-to-one relationship
  3. One-to-one relationship

Many-to-many relationship

It multiplexes the number of threads onto a smaller or equal number of kernel threads.

MANY-TO-ONE MODEL

Mapping many user-level threads to one kernel level thread are the function of many to one model. The thread library does this in the user space. The entire process will be blocked every time a thread makes a blocking system call. At the same time, only one thread can access the kernel. It is because the multiple threads are not able to run in the multiprocessors or parallel.

 

The system uses this type of relationship only when the operating system does not support the user-level threads.

ONE TO ONE MODEL

The relationship is between the user level and the kernel level thread. The effectiveness of the type of the model is high, and it provides more concurrency than the other models.

Advantage

  1. It lets the other thread to run every time the thread makes a blocking system call.
  2. It supports multiple threads for the execution of the microprocessors.

Disadvantage

Availability of the corresponding kernel thread for the creation of the user thread.

For example, OS/2, Windows 2000.

The article shows the relationship models in the most accessible language. Read the content and equate yourself.