Kernel-level threads and user-level threads

Source: Internet
Author: User

These two days in writing this blog, incidentally review the operating system information, encountered a previously not clear question, is about the kernel-level thread and user-level thread. After reviewing some information, I would give you a brief introduction.

Threads are already implemented in many systems. By then the various operating systems have not been implemented in exactly the same way.
In some systems, for example, the Infomix system is a database management system such as IBM's. User-level threads implemented (UserLevel Threads, ULT), and some systems such as (MAC OS's predecessor Macintosh and OS/2 operating system) implement kernel support threads (Kernel supported Threads, KST); There are also some Solaris operating systems that implement both types of threads at the same time.


KST:

Kernel Support threads are implemented in the core space. The kernel sets a thread control block in the core space for each thread to register the thread identifier, register value, status, priority, and so on for that thread. All operations on the thread, such as Create, Undo, and Toggle. is done through the system function call by the corresponding handler in the kernel, set the kernel support thread of the system, its scheduling is in the thread unit.

Strengths:
In multiprocessor systems, the kernel can schedule multiple threads in the same process to run parallel to multiple processors at the same time, assuming that one thread in the process is blocked and the kernel can dispatch a thread in the same process. Kernel support threads have very small data structures and stacks, and threads switch faster. Switching overhead is small, and the kernel itself can be implemented using multithreading.


Disadvantages:
Even if the CPU switches between multiple threads in the same process. Also needs to fall into the kernel, so its speed and efficiency are inferior to user-level threading.



ULT:

User-level threads exist only in user space, regardless of the kernel. As far as the kernel is concerned. It is simply managing the regular process-single-threaded process. The presence of user-level threads is not perceptible, and each thread control block is set in user space. All operations on the thread are also completed in the user space by the functions in the thread library. There is no need for kernel help ; a system with a user-level thread is set, and its dispatch is still in process.
Strengths:
Thread switching does not need to fall into the kernel, so the switching overhead is small. Very fast ; line libraries The scheduling algorithm of the user thread is independent of the scheduling algorithm of the OS. As a result, line libraries can provide a variety of scheduling algorithms for application selection . the implementation of a user-level thread is independent of the operating system platform.
Disadvantages:
System call blocking Problem: The application is speaking. The blockage of one thread will cause a blockage of all threads throughout the process, and multithreaded applications cannot enjoy the benefits of multiple processors in multiprocessor system.

combination mode:

The kernel supports the establishment, scheduling, and management of multi-kst threads, and at the same time, it also allows user applications to establish, schedule, and manage user-level threads ; some kernels support threads corresponding to multiple user-level threads, and the program Ape can adjust the number of kernel support threads according to application needs and machine configuration. To achieve a better effect.
Strengths:
Multiple threads within the same process can run concurrently on multiple processors at the same time, while plugging a thread. There is no need to jam the whole process .


Compare the two:

(1) Kernel support
User-level threads can be implemented in an OS that does not support threading.
Kernel support threads need to be supported by the OS kernel.


(2) Processor assignment
In a multiprocessor environment. Master for user-level threading. The kernel assigns only one processor at a time to a process. Process does not enjoy the advantages of multiprocessor;
When a kernel support thread is set, the kernel can dispatch multiple threads in an application to run concurrently on multiple processors at the same time, increasing the speed and efficiency of the program.

(3) Scheduling and thread run time
Set up a system with kernel support thread, its scheduling method and algorithm and process scheduling is very similar, just the dispatch unit is a thread;
For a system that only has a user-level thread set, the dispatched unit is still a process.


Therefore, under the same conditions, the kernel-supported threads usually get a lot of other CPU uptime than user-level threads.
(4) switching speed
User-level thread switching typically occurs between threads of an application without having to fall into the kernel, and the rules for switching are very easy, with switching speeds at least one order of magnitude faster than kernel support threads.

(5) System call
In a typical OS, many system calls can cause blockages.

When a user-level thread runs these system calls, the entire process is blocked, and when a kernel support thread runs these system calls. The kernel only plugs into this thread. However, other threads of the process that they belong to can still be dispatched to run.


Very much is copied from cc ppt, hope will help!


Kernel-level threads and user-level threads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.