In: Computer Science
Q1: Server Design Models: (explain clearly) a. For a multi-threaded server, describe the advantages of adopting the many-to-one threading model. b. For a multi-threaded server, describe the advantages of adopting the one-to-one threading model.
Multithreading Models
Some operating system provide a combined user level thread and Kernel level thread facility. Solaris is a good example of this combined approach. In a combined system, multiple threads within the same application can run in parallel on multiple processors and a blocking system call need not block the entire process. Multithreading models are three types
a.
Many to One Model
In the many-to-one model, you get concurrency (the appearance that tasks run at the same time).If the user level thread libraries are implemented in the operating system in such a way that system does not support them then Kernel threads use the many to one relationship modes.
The main problem with one-to-one model is that it places a restriction on you to be careful and frugal with threads, as each additional thread adds more "weight" to the process. Also it requires each thread to have its own kernel mode stack.
So using many-to-one threading model is benificial.
b.
One to One Model
In the many-to-one model, you get concurrency (the appearance that tasks run at the same time) but you can't get parallelism. There is only one kernel thread and that can't be spread over multiple processors.
In the one-to-one model, each user thread has a corresponding kernel thread, which gives the kernel more options to provide concurrency or even parallelism.
"one-to-one model," each thread really creates two threads: A kernel mode thread and a user mode thread. In reality, all that is needed a single thread that can operate in both user and kernel modes (i.e., a kernel mode stack).
The advantage a thread that can operate in both kernel and user mode (an possibly other modes as well, aka one-to-one model) is that the threads can operate completely independently and is likely simpler to implement. Each thread can enter kernel mode (e.g. perform I/O) without blocking any other thread.
The downside to many-to-many and many-to-one is that kernel mode becomes a resource whose unavailability can cause one group of threads to block another group of threads.
Let's say you have 3 kernel mode "threads" and 10 user mode threads. If 4 user mode threads try to do I/O at the same time, the 4th thread will block until one of the first three threads complete.
It is also more complicated to implement because you would have to manage the kernel mode "threads" as resources.
So it is better to use one-to-one model.