Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do user level threads (ULTs) and kernel level threads (KLTs) differ with regards to concurrent execution?

Here's what I understand; please correct/add to it:

In pure ULTs, the multithreaded process itself does the thread scheduling. So, the kernel essentially does not notice the difference and considers it a single-thread process. If one thread makes a blocking system call, the entire process is blocked. Even on a multicore processor, only one thread of the process would running at a time, unless the process is blocked. I'm not sure how ULTs are much help though.

In pure KLTs, even if a thread is blocked, the kernel schedules another (ready) thread of the same process. (In case of pure KLTs, I'm assuming the kernel creates all the threads of the process.)

Also, using a combination of ULTs and KLTs, how are ULTs mapped into KLTs?

like image 392
AbhinavChoudhury Avatar asked Feb 09 '13 21:02

AbhinavChoudhury


People also ask

What is the difference between user level threads and kernel level threads?

1. User threads are implemented by users. Kernel threads are implemented by Operating System (OS).

What are the differences between user level threads and kernel level threads under what circumstances one is better than other?

User-level threads are easier and faster to create than kernel-level threads. They can also be more easily managed. User-level threads can be run on any operating system. There are no kernel mode privileges required for thread switching in user-level threads.

How is user-level thread scheduling different to kernel level scheduling?

Switching between user-level threads is faster than between kernel threads since a context switch is not required. User-level threads may result in the kernel making poor scheduling decisions, resulting in slower process execution than if kernel threads were used. Many scheduling algorithms exist.

What are the differences between user level threads and kernel level threads discuss the ways in which a user thread library can be implemented using kernel threads?

Summary: The Major Difference between User Level and Kernel Level Thread is that User Level Threads is managed by the User. Kernel Level Threads managed by Operating System. All modern operating systems support the threading model. Implementation of a thread will change according to the operating system.


1 Answers

Your analysis is correct. The OS kernel has no knowledge of user-level threads. From its perspective, a process is an opaque black box that occasionally makes system calls. Consequently, if that program has 100,000 user-level threads but only one kernel thread, then the process can only one run user-level thread at a time because there is only one kernel-level thread associated with it. On the other hand, if a process has multiple kernel-level threads, then it can execute multiple commands in parallel if there is a multicore machine.

A common compromise between these is to have a program request some fixed number of kernel-level threads, then have its own thread scheduler divvy up the user-level threads onto these kernel-level threads as appropriate. That way, multiple ULTs can execute in parallel, and the program can have fine-grained control over how threads execute.

As for how this mapping works - there are a bunch of different schemes. You could imagine that the user program uses any one of multiple different scheduling systems. In fact, if you do this substitution:

Kernel thread <---> Processor core

User thread <---> Kernel thread

Then any scheme the OS could use to map kernel threads onto cores could also be used to map user-level threads onto kernel-level threads.

Hope this helps!

like image 70
templatetypedef Avatar answered Sep 18 '22 09:09

templatetypedef