Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Multi Threading Models in Process Management
Next article icon

Multi Threading Models in Process Management

Last Updated : 01 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
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
 


Next Article
Multi Threading Models in Process Management

K

kartik
Improve
Article Tags :
  • Operating Systems
  • Processes & Threads

Similar Reads

    Difference between Multiprocessing and Multithreading
    Multiprocessing uses multiple CPUs to run many processes at a time while multithreading creates multiple threads within a single process to get faster and more efficient task execution. Both Multiprocessing and Multithreading are used to increase the computing power of a system in different ways. In
    3 min read
    Introduction of Process Management
    Process Management for a single tasking or batch processing system is easy as only one process is active at a time. With multiple processes (multiprogramming or multitasking) being active, the process management becomes complex as a CPU needs to be efficiently utilized by multiple processes. Multipl
    8 min read
    Difference between Multitasking and Multiprocessing
    When it comes to analyzing the productivity of systems in the contemporary environment of computing, the concepts of multitasking and multiprocessing become prominent. Although both concepts are bound to how a computer processes work, their mode of function and their purpose are entirely dissimilar.
    5 min read
    Three State Process Model in Operating System
    Pre-requisites: States of a Process in Operating Systems, Two-State Process Model in Operating SystemIn this article, we'll be discussing a three-state process model in an operating system and also discussing the need for this process model, how the process executes, what will be the possible transi
    4 min read
    5 State Process Model in Operating System
    In an operating system (OS), managing how programs run and interact with system resources is crucial for efficient performance. The 5-state process model is a fundamental framework used by OSs to categorize and control the behavior of processes, which are individual instances of programs running on
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences