Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

one-to-one multi-threading model

In silberschatz "Operating System Concepts" book, section 4.3.2 says that

one-to-one model provides more concurrency than the many-to-one model by allowing another thread to run when a thread makes a blocking system call. It also allows multiple threads to run in parallel on multiprocessors.

I have two questions here:

  1. How can one thread be blocked and other mapped on kernel thread? Dont we know that if one thread is blocked, entire process of that user-level thread is blocked?
  2. The OS considers user-level threads as one thread only. It cant be assigned to multiple processors/cores. Isn't the below given line contradicting that idea?

    It also allows multiple threads to run in parallel on multiprocessors

like image 262
fresh learner Avatar asked Mar 06 '18 05:03

fresh learner


People also ask

What are multi threading models?

Multi threading-It is a process of multiple threads executes at same time. 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.

What are the disadvantages of a one to one multithreading model?

A disadvantage of the one to one model is that the creation of a user thread requires a corresponding kernel thread. Since a lot of kernel threads burden the system, there is restriction on the number of threads in the system.

What are the advantages of one to one thread model?

One-to-One Model This provides several advantages: Scalable parallelism. Because each kernel thread is actually a different kernel-schedulable entity, multiple threads can run concurrently on different processors.


1 Answers

Your understanding of user level threads and kernel level threads is not correct, in particular you need to understand how user level threads are mapped to kernel level threads. So first lets define some terms

Kernel thread

A thread (schedulable task) that is created and managed by the kernel. Every kernel level thread is represented by some data structure which contains information related to the thread. In the case of Linux it is task_struct. Kernel threads are the only threads that are considered by the CPU scheduler for scheduling.

Note : Kernel thread is a bit of misnomer as Linux kernel doesn't distinguish between a thread and a process, schedulable task would better describe this entity.

User thread

A thread that is created and managed by some library such as JVM above kernel level. The library that creates these threads is responsible for their management that is which thread runs and when.

User level to kernel level mapping

Now you can create as many user level threads as you want but to execute them you need to create some kernel level thread (task_struct). This creation of kernel level threads can be done in many ways

One to one model

In this case whenever you create a user level thread your library asks the kernel to create a new kernel level thread. In the case of Linux your library will use clone system call to create a kernel level thread.

Many to one model

In this case your library creates only one kernel level thread (task_struct). No matter how many user level threads you create they all share the same kernel level thread, much like the processes running on a single core CPU. The point to understand is that your library here acts much like the CPU scheduler, it schedules many user level threads on single kernel level thread.

Now to your question

The OS considers user-level threads as one thread only. It can’t be assigned to multiple processors/cores. Isn't the below given line contradicting that idea?

If you were using many to one model, in that case you will have only one kernel level thread for all of your user level threads and hence they cannot run on different CPU’s.

But if you are using a one to one model then each of your user level threads has a corresponding kernel level thread that can be scheduled individually and hence user level threads can run on different CPU’s given that you have more than one CPU.

like image 56
mightyWOZ Avatar answered Nov 04 '22 18:11

mightyWOZ