Multithreading Models in Operating System exhibit the ways of mapping the user threads to the kernel threads. Here, we will learn about the three multithreading models, Many to One model, One to One model and Many to Many model.
Many to One multithreading model maps many user threads to only one kernel thread. One to One multithreading model maps a single user thread to a single kernel thread. Many to Many multithreading models maps many user threads to a lesser or equal number of kernel threads.
There is much more to learn about these models. Proceeding further we will discuss each of these models briefly and we will also discuss the relating terms multithreading, user thread and kernel thread. So let’s start.
Contents: Multithreading Models in Operating System
Multithreading
As we know, each process has its own address space which contains code, data, files, registers, stack and a single thread of control. The process with a single thread of control is a traditional or classical process. Its drawback is that if the thread of the process gets blocked, the whole process will get blocked.
So the solution is to divide the single thread of control into multiple threads. The process with multiple threads can execute several tasks at a time. The multiple threads of the same process share the code, data and files of the process and each thread maintains its own register and stack. This is called multithreading and the process with multiple threads is called multithreaded process.
In the multithreaded process, even if one of the thread gets blocked it does not block the execution of the whole process as the processor can schedule another thread for execution. The simplest example of Multithreading is the word processor. The word process runs multiple threads at a time like a thread for displaying the graphics, the other for responding to the keystroke, say one for spell check, one for navigating a word or phrase on the page and so on.
User Thread
Threads that are implemented at the user level are termed as user-level thread. The thread management of user threads is done by the thread library present at the userspace. The kernel does not have any information about the user-level threads.
It’s up to the developer to program the application to be multithreaded using the routines present in the thread library. The thread library at the userspace has the code of creating and destroying the threads, or for passing the data message between the threads. The thread library is also responsible for scheduling the threads or for saving and restoring the context of the user threads.
Kernel Thread
The threads implemented at the kernel level are termed as kernel-level threads. The thread management is at the kernel level and the kernel threads cannot be managed by the code in the application level.
It is the job of the kernel to maintain complete information of the entire process. The kernel also maintains the information about every single thread that is present inside the process.
Multithreading Models in Operating System
1. Many to One Multithreading Model
Many to one multithreading model maps many user threads to a single kernel thread. The thread library present at the user space is responsible for thread management at the user level. The user threads do not require any kernel support.
In many to one model, a single user thread can access the kernel at a time. So, the multiple threads can’t run in parallel. In this scenario, if a thread makes a system blocking call the entire process can get blocked. As only one thread has the access to the kernel at a time.
This model is implemented by the Green Threads library of Solaris Operating system. This type of model is implemented by the operating systems that do not create kernel threads.
2. One to One Multithreading Model
One to one multithreading model maps one user thread to one kernel thread. So, for each user thread, there is a corresponding kernel thread present in the kernel. In this model, thread management is done at the kernel level and the user threads are fully supported by the kernel.
Here, if one thread makes the blocking system call, the other threads still run. So, when compared with many to one model, the one to one model provides more concurrency.
Implementing a kernel thread corresponding to each user thread increases the overhead of the kernel, resulting in slow thread management. So, the operating system implementing this model restricts the number of threads that can be supported by the system.
The operating system, Linux and Windows family implement one to one multithreading model.
3. Many to Many Multithreading Model
Many to many multithreading models in operating system maps many user threads to a lesser or equal number of kernel threads. This model does not suffer from any of the drawbacks of many to one model and one to one model.
Many to many multithreading models does not restrict the number of user thread created. The developer can create as many threads as required. Neither the process block if a thread makes a blocking system call. As the kernel can schedule other thread for execution.
There exist a variation in many to many model, which depicts that there can be a user thread that bounds to a kernel thread. This kind of model in multithreading is referred as the two-level model. This model provides efficient and fast thread management. The version older than Solaris 9 support the two-level model.
Key Takeaways
- Multithreading allows a process to get divided into small threads and increase CPU utilization.
- Many to One multithreading model maps many user threads to a single kernel thread and only one user thread has access to the kernel at a time. So, if one thread makes a system blocking call the entire process can get blocked.
- In One to one multithreading model, for each user thread, a corresponding kernel thread is created. So, a process doesn’t block even if a thread blocks as the kernel provides thread scheduling.
- In one to one multithreading model, the number of user threads is limited to reduce the overhead of the system.
- Many to many multithreading model maps many user threads to an equal or smaller number of kernel thread. It is very fast and flexible multithreading model.
The user thread and kernel thread share relationship with each other. Multithreading models provide three different ways of establishing the relationship between user thread and kernel thread which are discussed above.
Leave a Reply