Kernel-level threading (KLT) and user-level threading (ULT)

Source: Internet
Author: User

Kernel-level threading (KLT) and user-level threading (ULT)

TAGS:KLT ULT kernel-level thread user-level thread

Introduction: This article refers to the operating system kernel mode and user mode, if you do not understand, you can see my this article kernel mode and user mode, which is briefly described.

Processes and Threads

First of all, the advantages of a thread to the process, which is actually the meaning of the emergence of threads.
Process is the basic unit of resource ownership, process switching needs to save process state, which can cause resource consumption. A portion of a resource that the shared process obtains from a thread in the same process. In the same process, the switch of the thread does not cause the process to switch, and the switching of the thread requires less resources than the process switch, which can improve efficiency.

Kernel-level threading (Kemel-level Threads, KLT also has a thread called kernel support)
    • All work (creation and revocation) of thread management is done by the operating system kernel
    • The operating system kernel provides an API for application design interfaces for developers to use KLT

Pure kernel-level threading features:

  1. One of the threads in the process is blocked, and the other threads in the same process (ready state) occupy the processor running in the nuclear power dispatch
  2. In a multiprocessor environment, internal nuclear energy simultaneously dispatches multiple threads of the same process, mapping these threads to different processor cores to improve the execution efficiency of the process.
  3. Application threads run in the user state, thread scheduling and management are implemented in the kernel. When a thread is dispatched, control changes from one thread to another, requiring a mode switch and a large overhead.
User-level threads (User-level Threads ULT)
    • User space Run line libraries, any application can be designed as a multithreaded program by using line libraries. Thread libraries is a routine package for user-level thread management that provides the development and running support environment for multithreaded applications, including code for creating and destroying threads, code for passing data and messages between the threads, code to dispatch thread execution, and code to save and restore thread contexts.
    • So thread creation, message passing, dispatch, save/restore context are wired libraries to complete. The kernel does not perceive the existence of multithreading. The kernel continues with the process as the dispatch unit, and specifies an execution state (ready, running, blocking, and so on) for the process.

Features of pure user-level threading:

  1. Thread switching does not require kernel mode and can save schema switching overhead and kernel resources.
  2. Allows the process to schedule threads by selecting different scheduling algorithms for specific needs. The scheduling algorithm needs to be implemented by itself.
  3. Because it does not require kernel support, it can be run across the OS.
  4. Can not take advantage of multicore processors a bit, OS scheduling process, only one ult per process can execute
  5. A ult block that will cause the entire process to block.

Jacketing technology can solve the ult of a thread blocking causing the entire process to block.

The goal of jacketing is to convert a blocking system call into a non-blocking system call. For example, when a thread in a process calls IO to break money, it calls an application-level I/O jacket routine instead of calling a system I/O directly. Let this jacket routine check and determine if the I/O device is busy. If busy, jacketing gives control to the thread dispatcher of the process, determines that the thread is in a blocking state and transfers control to another thread (if no ready thread can perform a process switchover).

A combined strategy for threading implementation

As you can see, both the user-level thread and the kernel-level thread have their own advantages and disadvantages, and the main performance in the application is:

    • User-level multithreading has a good effect on dealing with logical parallelism. Not good at solving physical concurrency problems.
    • Kernel-level multithreading is suitable for solving physical parallelism problems.

Composition strategy:
Supported by the operating system kernel-level multi-threading, the operating system's library to support user-level multi-threading, thread creation is created entirely in user space, out-of-the-box scheduling is also within the application, and then the user-level multithreading map to (or is bound to) some kernel-level multithreading. programmers can adjust the number of kernel-level threads for different application characteristics to achieve the best solution for physical parallelism and logical parallelism.

Attach three kinds of threading pattern diagram to help understand ( from the Internet, the copyright can not be tested, such as the source may contact the author to delete or add Copyright instructions )


In fact, there is a light process concept, but I do not write in this article rather better understand. In addition, if there is a bad place to write, welcome to comment on the exchange.

Kernel-level threading (KLT) and user-level threading (ULT)

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: 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.