The difference between multithreading and multiple processes

Source: Internet
Author: User

1) Priority threads that need to be frequently created for destruction the most common application of this principle is the Web server, a connection to build a thread, a broken thread to destroy, if the process, the cost of creating and destroying is very difficult to withstand 2) need to do a lot of computing priority use of the thread so-called large computations, Of course is to consume a lot of CPU, switching frequently, this situation is the most suitable for the thread. The most common of this principle is image processing, algorithm processing. 3) strong correlation with threading, weak correlation processing with process what is strong correlation, weak correlation? It is difficult to define in theory, and to give a simple example to understand. The general server needs to do the following tasks: messaging, message processing. "Messaging" and "message processing" are weak-related tasks, and "message processing" may be divided into "message decoding", "Business processing", these two tasks are relatively much more relevant. So "messaging" and "message processing" can be divided into process design, "message decoding", "Business processing" can be divided into threading design. Of course, this classification is not static, but also can be adjusted according to the actual situation. 4) may be extended to multi-machine distribution using the process, multi-core distribution for threading reasons see above comparison. 5) to meet the needs of the situation, with you most familiar with the best way of "data sharing, synchronization", "Programming, debugging," "Reliability" the so-called "complex, simple" should be how to choose, I can only say: There is no clear method of choice. But I can tell you a choice principle: if multi-process and multi-threading can meet the requirements, then choose the one you are most familiar with and most adept at. Need to remind is: although I gave so many choice principle, but the actual application is basically "process + thread" combination way, do not really fall into a kind of error. Consume resources: From the kernel point of view, the purpose of the process is to assume the basic unit of allocating system resources (CPU time, memory, etc.). A thread is an execution flow of a process that is the basic unit of CPU dispatch and dispatch, which is a smaller unit that can run independently than a process. threads, which use the same address space with each other, share most of the data, start a thread that spends much less space than it takes to start a process, and the time it takes to switch between threads is much less than the time it takes to switch between processes. According to statistics, in general, the cost of a process is about 30 times times the cost of a thread, of course, on a specific system, this data may be significantly different. Communication: The transfer of data between processes can only be through the means of communication, that is time-consuming and inconvenient. Thread time data is most shared (not shared within thread functions) and is quick and easy. But data synchronization requires that locks pay particular attention to the thread's own advantages for static variables: Improve application responsiveness, and make multi-CPU systems more efficient. The operating system guarantees that when the number of threads is not greater than the number of CPUs, different threads run on different CPUs, and the program structure is improved. A bothLong, complex processes can be considered to be divided into multiple threads, becoming separate or semi-independent parts of the run, which are beneficial for understanding and modifying. 

  

The difference between multithreading and multiple processes

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.