Understand the concept and development of Linux Thread Technology

Source: Internet
Author: User
Understand the concept and Technology Development of Linux thread technology-Linux general technology-Linux programming and kernel information. The following is a detailed description. Author: Jiang Hong

Linux is a multi-user, multi-task operating system. Multi-User means that multiple users can use the computer system at the same time; multi-task means that Linux can execute several tasks at the same time, and it can execute another task when one task has not been completed. In the operating system design, a Thread is evolved from a Process. The main purpose is to better support multi-processor and reduce the overhead of context switching (Process/Thread.

Relationship between processes and threads

According to the definition of the operating system, a process is the minimum unit of system resource management, and a thread is the minimum unit of program execution. The thread and process are very similar. The difference is that the thread is smaller than the process.

First, threads use the design idea that multiple threads can share resources. For example, most of their operations are performed in the same address space. Second, switching from one thread to another costs less than the process. Again, the information of the process itself occupies more space in the memory than the thread.

Therefore, threads can make better use of memory. A thread can be seen as a specified sequence of execution within a process. The biggest difference between a thread and a process is that the thread shares the same address space and runs on the same address.

Linux thread Definition

Threads are concurrent multi-path execution paths in the shared memory space. They share the resources of a process, such as file descriptions and signal processing. When switching between two common processes (non-threads), it is costly for the kernel to switch from the context of one process to the context of another process.

Here, the main task of context switching is to save the CPU status of the old process, load the Save status of the new process, and replace the memory image of the old process with the memory image of the new process. The thread allows the process to switch between several running tasks without executing the complete Context mentioned above.

In Unix systems, there have been some different thread standards, all of which support Portable Operating System Interface Standard POSIX (Portable Operating System Interface Standard ).

POSIX standards are developed by IEEE and accepted by the International Standardization Organization as international standards. POSIX 1003.1c is a standard used for threads (code segments currently executed in a program). It was previously part of P1993.4 or POSIX.4 and was passed by IEEE in 1995, classified as ISO/IEC 9945-1: 1996.

This article describes the threads mainly for POSIX Threads, that is, Pthread, because Linux has the best support for it. A thread is a concept closer to the execution body. It can share data with other threads in the process, but has its own stack space and independent execution sequence. Threads and processes are introduced on the basis of a serial program to improve program concurrency and program running efficiency and response time.

You can also regard threads and lightweight processes (LWP) as equivalent, but there are different interpretations in different systems/implementations. LWP can be interpreted as a virtual CPU or kernel thread, which can help user-state threads implement some special functions. Pthread is a standardized model that divides a program into a group of tasks that can be executed simultaneously.
Related Article

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.