LINUX multi-thread Learning (1)

Source: Internet
Author: User


Process is the basic unit of program execution and resource allocation in the system. Each process has its own data segment, code segment, and stack segment, which causes the process to play a field protection role during switchover and other operations. However, in order to further reduce the idling time of the processor and reduce the overhead of context switching, another concept emerged in the process evolution. This is a thread, also known as a lightweight process. It is the basic scheduling unit in a process. Threads are concurrent multi-path execution paths in the shared memory space. They share the resources of a process, such as file descriptors and signal processing. Therefore, context switching overhead is greatly reduced.

Like a process, a thread has a control table, where the thread places related variable values in the thread control table. A process can have one or more threads, that is, multiple thread control tables and stack registers. But they share a memory space, which results in the impact of operations on each thread on other threads. Therefore, thread synchronization is very important.

Threads can be divided into user-level threads and core-level threads.
(1) user-level threads are mainly used to solve the problem of upstream/downstream switching. The scheduling algorithm and scheduling process are determined by the user's own choice, and the specific kernel support is not required during running, the operating system provides a library function, including thread creation, scheduling, and revocation. However, the kernel still manages processes. If a thread in a process calls a blocked system call, the process and other threads in the process will be blocked, which cannot take advantage of the multi-processor.
(2) The core-level thread allows the threads in different processes to be scheduled according to the same relative priority scheduling method. This gives full play to the role of multi-processor.

Currently, most systems use a combination of user-level and core-level methods. A user-level thread can correspond to one or more core-level threads, which can meet the needs of a multi-processor system, you can also minimize the scheduling overhead.

In the course of Linux development, we started to support threads in a non-real sense, to the emergence of a one-to-one thread model (a user-level thread corresponds to a kernel-level thread ), now nptl has made great improvements, but it still uses a one-to-one thread model.

~~ End ~~

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.