 Hello everyone. Today we are going to learn about multi-threading models. The learning outcome of this session are at the end of this session student will be able to compare user threads and kernel threads and summarize different thread models. Recall from last video that thread is nothing but basic unit of CPU utilization. There are two types of threads, user thread and kernel thread. User thread are associated with user space while kernel thread is associated with operating system. User threads are created by user thread library while kernel threads are managed by operating system. Let us see user level thread. User level threads are managed by user. Here kernel is not aware of the existence of the thread. As shown in this figure, we have process one and process two. Both processes contain three threads and we have a thread library. All these threads are present in user space. Here the thread library is responsible for creating and destroying threads. Also it is responsible for passing messages and data between threads. The thread scheduling and execution is also done by thread library. Thread library also supports for saving and restoring the thread context whenever there is switching between the threads within a process. The advantages of user level threads are thread switching does not require kernel mode privileges because these threads are created in user space and these threads are created by user library. User level thread can run on any type of operating system. Scheduling can be application specific in the user level thread. User level threads are fast to create and manage. These are all advantages of user level thread. Only these advantages associated with user level thread is if your system is uniprocessor system and it works on a single thread model then if thread blocks then whole system may block. Let us see kernel level thread. Here the thread management is done by kernel. No thread management code is present in application area means application area means it is user space but it is not there. The kernel thread is not present in application area it is only present in kernel area. So kernel threads are supported directly by operating system. Any application can be programmed to be multithreaded using kernel level threads. All of the threads within an application are supported within a single process. Kernel maintains context information for the process as a whole and for individual thread within the process. Here scheduling of kernel thread is done by kernel itself and it is based on threads. The kernel performs thread creation scheduling and management in kernel mode. Kernel threads are generally slow to create and manage than the user level threads. The advantages of kernel threads are kernel can simultaneously schedule multiple threads from the same process on multiple processes. If one thread in a process is blocked the kernel can schedule another thread of the same process but system does not block because here we have another thread from that same process. Kernel routines themselves can be multithreaded. This advantage of kernel thread is kernel threads are generally slow to create and manage than user level threads because here operating system take part in creation of kernel level threads. Transfer of control from one thread to another thread within the same process is user mode switch to the kernel mode. Now just pause a video and differentiate between user level thread and kernel level thread. Now let us see the difference between user level thread and kernel level thread. User level threads are faster to create and manage while kernel level threads are slower to create and manage. The implementation is by thread library at user level while for kernel thread operating system supports creation of kernel threads. User level thread is generic and can run on any type of operating system while kernel level thread is specific to the operating system. Here in user level thread multithreaded applications cannot take advantage of multi processing while in kernel thread kernel routine themselves can take an advantage of multithreaded because they themselves are multithreaded. Now let us see multithreading model. Now what is multithreading? Multithreading means a process contains multiple thread which performs multiple tasks at a time. So here a user process wants to create one or more threads. Then kernel can create one or more threads for the process. Even a kernel does not support threading it can create one thread per process that is it can create a process with a single thread of control. This means that each and every process is associated with single thread of control. Process is associated with single thread always. Finally a relationship must exist between user thread and kernel thread because in user space also we are using process. In kernel thread also we are using process. So processes each process is associated with thread. So there must be relationship between user thread and kernel thread. There exist three common ways of establishing such a relationship that is many to one model, one to one model and many to many model. Let us see these models in detail. First model is many to one model. Now in many to one model we have many user level threads mapped to single kernel level thread as shown in this figure. We have many user level threads which are mapped to single kernel level thread. Here these type of threads are used in Solaris green threads or GNU portable threads. All these user threads are created in user space using thread library. So thread management is done at user space by thread library. Kernel supports in this case kernel supports only the process concept not the threading concepts. Only user threads are created in user mode and they are mapped to single kernel thread. Only one user thread can use a kernel thread at a time. Next model is one to one model. Now here kernel may implement threading and can manage threads schedule and they can also schedule threads. Now as shown here one to one model here each user level thread is mapped to each kernel level thread. So mapping is one to one that user level thread is created at user space using thread library and kernel level threads are created at kernel using operating system. Now here kernel is aware of all these threads. So recent operating systems Windows Linux all operating systems supports this one to one model. All these kernels having thread supports they can schedule processes and their threads then not only the process means in this case whenever kernel schedules a process it schedules process along with its thread not only it does not schedule only the process. So thread scheduling is also done. So this is what the user and kernel model that is one to one model each user thread is mapped to each kernel level thread. Now next model is menu to menu model. Now in menu to menu model it allows many user level thread to be mapped to smaller or equal number of kernel threads. So here we have four user threads which are mapped to three kernel level thread. Means here the kernel threads can be three or it can be four means less than four but not greater than four. It allows operating system to create a sufficient number of kernel threads. So depending on number of user threads all kernel threads are created but kernel number of kernel thread should not extend the number of user threads. This menu to menu model is used in Solaris prior to version 9 or it also used in Windows NT or 2000 with the thread fiber package. So this menu to one model is supported by Solaris and Windows NT or Windows 2000. Now here in menu to menu model we can see these are all user threads which are mapped to kernel threads. User threads are supported by thread library at user space while kernel threads are created by operating system. In one to one model the one drawback of one to one model is each user level thread need to create corresponding kernel level thread. Now as we seen here different types of threads that is user thread, kernel thread and types of thread models that is menu to one, one to one and menu to menu model. So most recent operating system uses one to one model. So these are the references for this video. Thank you.