Operating System - Multithreading Models
Overview
In this page, we are going to learn about multithreading models, One to one thread model, Many to One thread model, Many to Many Thread model, Drawbacks of thread models and about Thread libraries
Types of multithreading models
- One-to-One
- Many-to-One
- Many-to-Many
One-to-One Model
- There may be one to one relationship between user thread and kernel thread.
- Each user thread can maps the corresponding kernel thread.
- It execute the another thread when a thread makes a blocking system call.
- It is more concurrency than others.
- On multiprocessor system, it allows multiple threads to be executed in parallel.
- This model is used by most of the operating-system such OS/2, Windows 95,98,NT,2000 and XP.
- Drawback: creating a user thread requires creating the corresponding kernel thread.
Many-to-One Model
- Many user threads map to a single kernel thread.
- Thread library is used to support and manage the thread in user space.
- If a thread makes a blocking system call, then the entire process will be blocked.
Many-to-Many Model
- Many user threads map to less or equal number of kernel threads.
- Based on the requirement, the developer can create many user threads and corresponding kernel threads but the kernel can schedule only one thread at a time.
- It is also referred as two-level thread in which a user thread to be bound to a kernel thread.
Thread libraries
It provides an API for thread creation and maintenance. This API is used by the developer to create and manage the thread. There are two ways for implementing thread libraries
User-level libraries
User-level libraries provide the entire libraries in the user space without kernel support. That means all the code and data structures of the library present in the user space.
Kernel-level libraries
Kernel-level libraries implement the functions which is supported directly by the operating-system.
Thread libraries in use
- POSIX Pthread provides either user-level or kernel-level library.
- Win32 provides kernel-level library which is available on Windows system.
- Java provides thread creation and management directly from within a Java program.