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

Source: Internet
Author: User

Operating System-Thread (3) user space and kernel space implementation Thread
Main content of this article: introduction to operating system User space and kernel space introduction to User space Implementation of threads in the kernel space Implementation of thread User space and kernel space mixed use of threads I. 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: the kernel space is used to run the core components of the operating system, such as memory management components and IO interaction components, file Management and interrupt management components, and drivers also run in the kernel space. User space used to run common applications.: 2. In the user space, threads implementing the thread user space are 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 The advantage of thread creation is that run-Time system is completed by calling the Procedure of the existing Library, and the overhead of process creation and destruction is very small. Because the kernel is not aware of threads, the threads in the user space can run in an operating system that does not support threads. Because the threads are maintained during the same runtime, they are inside the same process, thread switching does not have to deal with the kernel, so the overhead of switching between threads is very small, there is no Context Switch, and there is no memory cache refresh reset. The thread in the user space can customize the scheduling algorithm. programmers can write a set of Thread Scheduling Algorithms for their own programs. The 2.2 disadvantage is that for the kernel, no matter how many threads are in the process, the kernel processes this process according to the single-threaded process. Therefore, only one thread can run in a single process at a unified time. Even if multiple CPUs are idle, only one thread can run, therefore, resources cannot be used to the maximum extent. Of course, because only one thread can run, when a thread is blocked, the whole process will be blocked. For a single-process system, if a user-state thread is started, it will always run and cannot be switched to another thread. This is related to the first thread. For the CPU, this process has only one thread, and because it is a single process, there will be no interruption (trap, Interrupt) requests to switch the cpu to other processes. Of course, this problem allows users to implement their own algorithms for scheduling and improvement (implemented in the run-time system) 3. All threads that implement the thread kernel space in the kernel space are created by the operating system kernel, shows the implementation. 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. The 3.1 advantage thread table contains the threads of all processes, multiple Threads of all processes running one thread simultaneously on multiple CPUs are not blocked. The cpu will check whether other threads can run. 3.2 disadvantage 1. The creation thread consumes a lot and needs to be switched between the user space and the kernel. 2. Of course, in case of thread Context switching, the program must also switch between the user and kernel states, overhead 4. There are obvious advantages and disadvantages for mixed use of the preceding two thread implementation methods between user space and kernel space threads. 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.