Open In App

Multi Threading Models in Process Management

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

Multi threading- It is a process of multiple threads executes at same time.

There are two main threading models in process management: user-level threads and kernel-level threads.

User-level threads: In this model, the operating system does not directly support threads. Instead, threads are managed by a user-level thread library, which is part of the application. The library manages the threads and schedules them on available processors. The advantages of user-level threads include greater flexibility and portability, as the application has more control over thread management. However, the disadvantage is that user-level threads are not as efficient as kernel-level threads, as they rely on the application to manage thread scheduling.

Kernel-level threads: In this model, the operating system directly supports threads as part of the kernel. Each thread is a separate entity that can be scheduled and executed independently by the operating system. The advantages of kernel-level threads include better performance and scalability, as the operating system can schedule threads more efficiently. However, the disadvantage is that kernel-level threads are less flexible and portable than user-level threads, as they are managed by the operating system.

There are also hybrid models that combine elements of both user-level and kernel-level threads. For example, some operating systems use a hybrid model called the “two-level model”, where each process has one or more user-level threads, which are mapped to kernel-level threads by the operating system.

Overall, the choice of threading model depends on the requirements of the application and the capabilities of the underlying operating system.

Here are some advantages and disadvantages of each threading model:

User-level threads:

Advantages:

Greater flexibility and control: User-level threads provide more control over thread management, as the thread library is part of the application. This allows for more customization and control over thread scheduling.

Portability: User-level threads can be more easily ported to different operating systems, as the thread library is part of the application.

Disadvantages:

Lower performance: User-level threads rely on the application to manage thread scheduling, which can be less efficient than kernel-level thread scheduling. This can result in lower performance for multithreaded applications.

Limited parallelism: User-level threads are limited to a single processor, as the application has no control over thread scheduling on other processors.

Kernel-level threads:

Advantages:

Better performance: Kernel-level threads are managed by the operating system, which can schedule threads more efficiently. This can result in better performance for multithreaded applications.

Greater parallelism: Kernel-level threads can be scheduled on multiple processors, which allows for greater parallelism and better use of available resources.

Disadvantages:

Less flexibility and control: Kernel-level threads are managed by the operating system, which provides less flexibility and control over thread management compared to user-level threads.

Less portability: Kernel-level threads are more tightly coupled to the operating system, which can make them less portable to different operating systems.

Hybrid models:

Advantages:

Combines advantages of both models: Hybrid models combine the advantages of user-level and kernel-level threads, providing greater flexibility and control while also improving performance.

More scalable: Hybrid models can scale to larger numbers of threads and processors, which allows for better use of available resources.

Disadvantages:

More complex: Hybrid models are more complex than either user-level or kernel-level threading, which can make them more difficult to implement and maintain.

Requires more resources: Hybrid models require more resources than either user-level or kernel-level threading, as they require both a thread library and kernel-level support.

Many operating systems support kernel thread and user thread in a combined way. Example of such system is Solaris. Multi threading model are of three types. 
 

Many to many model.
Many to one model.
one to one model.

Many to Many Model 

In this model, we have multiple user threads multiplex to same or lesser number of kernel level threads. Number of kernel level threads are specific to the machine, advantage of this model is if a user thread is blocked we can schedule others user thread to other kernel thread. Thus, System doesn’t block if a particular thread is blocked. 

It is the best multi threading model.

many_to_many

Many to One Model 

In this model, we have multiple user threads mapped to one kernel thread. In this model when a user thread makes a blocking system call entire process blocks. As we have only one kernel thread and only one user thread can access kernel at a time, so multiple threads are not able access multiprocessor at the same time. 

The thread management is done on the user level so it is more efficient.
 

many_to_many

One to One Model 

In this model, one to one relationship between kernel and user thread. In this model multiple thread can run on multiple processor. Problem with this model is that creating a user thread requires the corresponding kernel thread. 

As each user thread is connected to different kernel , if any user thread makes a blocking system call, the other user threads won’t be blocked.

many_to_manyThread Libraries:

A thread library provides the programmer with an API for creating and managing threads. There are two primary ways of implementing a thread library. The first approach is to provide a library entirely in user space with no kernel support. All code and data structures for the library exist in user space. This means that invoking a function in the library results in a local function call in user space and not a system call. The second approach is to implement a kernel-level library supported directly by the operating system. In this case, code and data structures for the library exist in kernel space. Invoking a function in the API for the library typically results in a system call to the kernel.

Three main thread libraries are in use today: POSIX Pthreads, Windows, and Java. Pthreads, the threads extension of the POSIX standard, may be provided as either a user-level or a kernel-level library. The Windows thread library is a kernel-level library available on Windows systems. The Java thread API allows threads to be created and managed directly in Java programs.

Advantages of Multithreading in OS:

  • Minimize the time of context switching- Context Switching is used for storing the context or state of a process so that it can be reloaded when required.
  • By using threads, it provides concurrency within a process- Concurrency is the execution of multiple instruction sequences at the same time.
  • Creating and context switching is economical – Thread switching is very efficient because it involves switching out only identities and resources such as the program counter, registers, and stack pointers.
  • Allows greater utilization of multiprocessor architecture

Disadvantages of Multithreading in OS:

  • A multithreading system operates without interruptions.
  • The code might become more intricate to comprehend.
  • The costs associated with handling various threads could be excessive for straightforward tasks.
  • Identifying and resolving problems may become more demanding due to the intricate nature of the code.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
 



Last Updated : 01 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads