Operating System-Thread (3) user space and kernel space implementation thread, Thread thread

Source: Internet
Author: User

Operating System-Thread (3) user space and kernel space implementation thread, Thread thread

Main content of this article:

1. Introduction to user space and kernel space

User space: User Space, Kernel space: Kernel Space. These two are one of the important concepts of the operating system. Today we will give a brief introduction to the thread:

:

 

2. Implement threads in the user space

The thread of the user space is created by the process through some existing libraries. The kernel of a non-system call is unknown. Shows the implementation.

 

In the user space, the implementation thread runs in the runtime system (run-time system ). The kernel knows nothing about this. For the kernel, it is only processing a single thread process. When implementing threads in a user space, each process maintains a Thread Table for its own threads. This Table stores various variables for running threads, such as registers, PCs, the thread table is maintained by the running system of the process. When a thread is blocked, its current running status is saved in the thread table. When it is started again, it also reads the saved status in the thread table and runs it again.

2.1 Advantages 2.2 disadvantages 3. Implementing threads in the kernel space

All threads in the kernel space are created by the operating system kernel, as shown in.

 

The kernel Thread also has a Thread table. However, this Thread table is stored in the kernel. It has the same functions as the user space Thread table and is used to store Thread data. Thread Scheduling is implemented by the operating system kernel.

The kernel thread and the user space thread are basically opposite in terms of performance

3.1 advantages 3.2 disadvantages

1. The creation thread consumes a lot and needs to be switched between the user space and the kernel.

2. Of course, when thread Context switching occurs, the program also needs to switch from the user State to the kernel state, causing high overhead.

4. Mixed use of user space and kernel space threads

The preceding two methods of thread implementation have obvious advantages and disadvantages. The best solution is to combine the two. A program can have both user space threads and kernel space threads.

The specific implementation method is that the kernel thread can have a part of user space on top of it. The kernel only schedules the kernel threads.

How to Implement the proportion. Return to the topic of program = Data Structure + algorithm...

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.