Operating systems-user-level threads and kernel-level threads

Source: Internet
Author: User

In multi-threaded operating systems, each system is implemented differently. A user-level thread is implemented in some systems, and a kernel-level thread is implemented in some systems

1. Kernel-level threading:

(1) thread creation, revocation, and switching, all require the kernel to implement directly, that is, the kernel to understand each of the threads as a scheduled entity.

(2) These threads can compete for resources across the system.

(3) A thread control block (TCB) is set up within the kernel space for each kernel support thread, and the kernel is aware of the existence of the thread and controls it based on that control block.

To some extent similar to a process, only the cost of creating and scheduling is smaller than the process. Some statistics are 1:10.

2. User-Level threads:

(1) User-level threads exist only in user space. -Contrast cores (3)

(2) The kernel is not able to see the user thread. -Important differences

(3) The allocation of kernel resources is still allocated according to the process, and the individual user threads can only compete within the process for resources.

The user thread runs on top of an intermediate system. There are two ways in which the intermediate system is implemented, namely the runtime System (Runtimesystem) and the kernel control thread.

The runtime system is essentially a collection of functions that are used to manage and control threads. Functions that include creation, revocation, thread synchronization and communication, and scheduled functions. These functions reside in user space as an interface between the user thread and the kernel. The user thread cannot use a system call, but when the thread needs system resources, the request is routed to the runtime, which obtains the system resources through the appropriate system calls.

Kernel Control Threads:

The system is assigned to several lightweight processes (LWP) in the process, and LWP can obtain the services provided by the kernel through system calls, while the user threads in the process can be reused to correlate to the LWP to obtain the service of the kernel.

Benefits of Kernel Threading:

(1)

(2) When there are multiple processors, multiple threads of a process can execute simultaneously

Disadvantages:

(1) dispatch by the kernel

Advantages of the user process:

(1) Thread scheduling does not require the kernel to participate directly, the control is simple

Disadvantages:

(1) Resource scheduling according to the process, multiple processors, the same process threads can only be reused under the same processor.

===========================================

The implementation of threads can be divided into two categories: User-level threads (user-level thread) and kernel thread threads (kernel-level thread). The latter is also known as a kernel-supported thread or lightweight process.

A user thread is a thread implemented in a user program that does not require kernel support and is not dependent on the operating system core, and the application process uses line libraries to provide functions to create, synchronize, dispatch, and manage threads to control the user thread.

Kernel thread: Created and revoked by the operating system kernel. The kernel maintains the context information of processes and threads, as well as thread switching. A kernel thread is blocked due to I/O operations and does not affect the operation of other threads. Windows NT and 2000/XP support kernel threads


User thread: Created and managed by the application process using line libraries, not since the operating system core. No need for user-state/kernel-mindset switching, fast. The operating system kernel does not know the existence of multithreading, so one thread blocking will cause the entire process (including all its threads) to block. Because the processor time slice allocation here is in the process as the basic unit, each thread executes relatively less time.

Windows NT and OS/2 support kernel threads. Linux supports core-level multithreading

=========================================================

Learned about user-level threading and kernel-level threading.

User-Level threads:

As you can see from the graph above, the management of user-level threads is done by the application process, not the kernel. In the kernel it is still only the concept of process, so the scheduling of threads can be set by the application itself, without the privilege of nuclear mentality.

But also because of this, there is no thread concept in the kernel, if a thread goes into the kernel and then blocks when the system calls, then the core will only block it as the entire process, which means that all the threads in the process are blocked.

The thread state and process state are independent (where do you start?). Do not understand)

Advantages:
Thread switching does not call the core
Scheduling is application-specific: You can choose the best algorithm
Ult can be run on any operating system (requires only line libraries)

Disadvantages:
Most system calls are blocked, so the core blocks the process, so all threads in the process will be blocked
The core only assigns the processor to the process, and two threads in the same process cannot run on two processors at the same time

Kernel-Level threads:

All thread management is done by the core
No line libraries, but provides API for core threading tools
The context of the core maintenance process and thread
Core support required for switching between threads
Scheduling on a thread-based basis
Example: Windows

Advantages:
For multiprocessor, the core can simultaneously dispatch multiple threads of the same process
Blocking is done at the thread level
The core routines are multithreaded
Disadvantages:
Thread switching within the same process calls the kernel, causing speed drops

Operating systems-user-level threads and kernel-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.