Multi-threaded switching and multi-process switching __linux for "Swoole Basics" Linux

Source: Internet
Author: User

The elephant will be installed in a refrigerator, a total of three steps, a refrigerator door open, two elephants into, three refrigerator door close, simple and rough. Unfortunately, our process and the conversion of the thread is not the elephant refrigerator problem, not nonsense, back to the point.
General process switching is divided into two steps
First of all
Toggles the page directory to use the new address space
And then
Toggle kernel stack and hardware context

For our Linux, the address space is the biggest difference between thread and process, if we are threading switch, we do not need to do the first step, that is, to switch the page directory to use the new address space. But switching the inner arc stack and hardware context is what we need to do for both thread switching and process switching.

The comparison between the two

Overall, there is no best, only the most suitable.
(1) Priority threads that need to be frequently created for destruction.
Eg:web server. To create a thread, break it and destroy the thread. The cost of creating and destroying the process is hard to bear.
(2) Priority threads requiring a large number of computations.
The so-called large number of calculations, is to consume a lot of CPU, switching frequently.
Eg: image processing, algorithm processing
(3) strongly related to the processing of the thread, if the relevant processing of the process.
What is called strong correlation, weak correlation. Let's give a simple example to illustrate:
The typical server needs to accomplish the following tasks: Messaging and message processing. Messaging and message processing is a weak-related task, and message processing may be divided into message decoding, business processing, the two tasks are relatively strong correlation. Therefore, messaging and message processing can be divided into process design, message decoding and business processing can be divided into thread design.
(4) A thread that may be extended to a multiple-machine distribution using a process, multi-core distribution.
(5) Meet the needs of the situation, with your most familiar, the most famous way.

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.