----Multithreading technology for advanced programming in the UNIX environment (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 snippet, and stack segment, which causes the process to perform on-site protection, such as switching. However, in order to further reduce the idling time of the processing machine to support multiprocessor and reduce the cost of context switching, there is another concept in the process evolution, which is the thread, also known as the lightweight process. It is a basic scheduling unit within a process. Threads are concurrent multipath execution paths in shared memory space that share resources for a process, such as file descriptors and signal processing. Therefore, the overhead of context switching is greatly reduced.

threads, like processes, have a control table that threads the associated variable values into the thread control table. A process can have one or more threads, that is, multiple thread control tables and stack registers. However, they share a single memory space, which results in the operation of each thread affecting other threads. So the synchronization of threads is very important.

threads can be divided into user-level threads and core-level threads.
(1) The user-level thread is mainly to solve the problem of switching between the top and bottom, its scheduling algorithm and scheduling process is the user's own choice of decision, at run time does not need a specific kernel support, the operating system will provide a library function, including the creation of threads, scheduling, revocation and other functions. And the kernel still manages the process. If a thread in a process invokes a blocked system call, the process and other threads in the process are blocked, which does not give the advantage of multiprocessor.
(2) Core-level threads allow threads in different processes to be dispatched according to the same relative-priority scheduling method. This enables the full use of multiprocessor functions.

Most systems now use a combination of user-level and core-level methods, and a user-level thread can correspond to one or more core-level threads, both to meet the needs of multiprocessor system and to minimize scheduling overhead.

In the development of Linux, in the beginning, not the true meaning of the support thread, to the emergence of one-to-one threading model (a user-level thread corresponding to a kernel-level thread), and now NPTL, there is a great improvement, but still use a one-to-one threading model.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

----Multithreading technology for advanced programming in the UNIX environment (1)

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.